Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit f82bc07

Browse files
committed
Release 1.0.1.5
1 parent 90e0bfe commit f82bc07

10 files changed

Lines changed: 70 additions & 92 deletions

File tree

Nuget/ACBr.Net.DFe.Core.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ACBr.Net.DFe.Core</id>
5-
<version>1.0.1.5-rc1</version>
5+
<version>1.0.1.5</version>
66
<title>ACBr.Net.DFe.Core</title>
77
<authors>Grupo ACBr.Net</authors>
88
<owners>Grupo ACBr.Net</owners>
@@ -14,7 +14,7 @@
1414
<language>pt-BR</language>
1515
<tags>ACBr ACBr.Net Automação Comercial</tags>
1616
<dependencies>
17-
<dependency id="ACBr.Net.Core" version="1.0.1.3-rc1" />
17+
<dependency id="ACBr.Net.Core" version="1.0.1.3" />
1818
</dependencies>
1919
</metadata>
2020
<files>

src/ACBr.Net.DFe.Core.Tests/ACBr.Net.DFe.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</PropertyGroup>
3535
<ItemGroup>
3636
<Reference Include="ACBr.Net.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3bb9130f8b775a6, processorArchitecture=MSIL">
37-
<HintPath>..\packages\ACBr.Net.Core.1.0.1.3-rc1\lib\net40\ACBr.Net.Core.dll</HintPath>
37+
<HintPath>..\packages\ACBr.Net.Core.1.0.1.3\lib\net40\ACBr.Net.Core.dll</HintPath>
3838
<Private>True</Private>
3939
</Reference>
4040
<Reference Include="System" />

src/ACBr.Net.DFe.Core.Tests/SerializerTest.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,26 @@ public void TestSerializer()
7676

7777
Assert.True(xmlDocument.Root.HasAttributes, "Erro ao serializar atributos do root.");
7878
Assert.True(xmlDocument.Root.Attributes().Count() == 1, "Erro ao serializar atributos do root.");
79-
Assert.True(xmlDocument.Root.FirstAttribute.Name == "id", "Erro ao serializar atributo id do root.");
80-
Assert.True(xmlDocument.Root.FirstAttribute.Value == "01", "Erro ao serializar atributo id do root.");
79+
Assert.True(xmlDocument.Root.FirstAttribute.Name == "id", "Erro ao serializar atributo id do root. Atributo com nome errado!");
80+
Assert.True(xmlDocument.Root.FirstAttribute.Value == "01", "Erro ao serializar atributo id do root. Valor incorreto!");
8181

8282
var nodes = xmlDocument.Root.Nodes();
8383
Assert.True(nodes.Count() == 14, "Erro ao serializar dados do xml.");
84+
85+
File.Delete("teste.xml");
86+
}
87+
88+
[Fact]
89+
public void TestDeserializer()
90+
{
91+
var xml = GenerateXml();
92+
93+
var serializer = DFeSerializer.CreateSerializer<TesteXml>();
94+
serializer.Serialize(xml, "teste.xml");
95+
96+
var item = serializer.Deserialize("teste.xml");
97+
98+
File.Delete("teste.xml");
8499
}
85100
}
86101
}

src/ACBr.Net.DFe.Core.Tests/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="ACBr.Net.Core" version="1.0.1.3-rc1" targetFramework="net45" />
3+
<package id="ACBr.Net.Core" version="1.0.1.3" targetFramework="net45" />
44
<package id="xunit" version="2.1.0" targetFramework="net45" />
55
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
66
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />

src/ACBr.Net.DFe.Core/ACBr.Net.DFe.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</PropertyGroup>
5252
<ItemGroup>
5353
<Reference Include="ACBr.Net.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3bb9130f8b775a6, processorArchitecture=MSIL">
54-
<HintPath>..\packages\ACBr.Net.Core.1.0.1.3-rc1\lib\net40\ACBr.Net.Core.dll</HintPath>
54+
<HintPath>..\packages\ACBr.Net.Core.1.0.1.3\lib\net40\ACBr.Net.Core.dll</HintPath>
5555
<Private>True</Private>
5656
</Reference>
5757
<Reference Include="ExtraConstraints, Version=1.10.9.0, Culture=neutral, PublicKeyToken=8b9afd7f380a7d64, processorArchitecture=MSIL">

src/ACBr.Net.DFe.Core/Collection/DFeCollection.cs

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,36 @@
1010
// The MIT License (MIT)
1111
// Copyright (c) 2016 Grupo ACBr.Net
1212
//
13-
// Permission is hereby granted, free of charge, to any person obtaining
14-
// a copy of this software and associated documentation files (the "Software"),
15-
// to deal in the Software without restriction, including without limitation
16-
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17-
// and/or sell copies of the Software, and to permit persons to whom the
13+
// Permission is hereby granted, free of charge, to any person obtaining
14+
// a copy of this software and associated documentation files (the "Software"),
15+
// to deal in the Software without restriction, including without limitation
16+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+
// and/or sell copies of the Software, and to permit persons to whom the
1818
// Software is furnished to do so, subject to the following conditions:
19-
// The above copyright notice and this permission notice shall be
19+
// The above copyright notice and this permission notice shall be
2020
// included in all copies or substantial portions of the Software.
21-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24-
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26-
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2727
// DEALINGS IN THE SOFTWARE.
2828
// </copyright>
2929
// <summary></summary>
3030
// ***********************************************************************
3131

3232
using System;
3333
using System.Collections.Generic;
34-
using System.Linq;
35-
using ACBr.Net.Core.Generics;
3634

3735
namespace ACBr.Net.DFe.Core.Collection
3836
{
39-
/// <summary>
40-
/// Classe GenericNFeCollection.
41-
/// </summary>
42-
/// <typeparam name="T"></typeparam>
43-
public class DFeCollection<T> : GenericCollection<T> where T : class
44-
{
37+
/// <summary>
38+
/// Classe GenericNFeCollection.
39+
/// </summary>
40+
/// <typeparam name="T"></typeparam>
41+
public class DFeCollection<T> : List<T> where T : class
42+
{
4543
#region Constructors
4644

4745
/// <summary>
@@ -56,9 +54,9 @@ public DFeCollection()
5654
/// </summary>
5755
/// <param name="source">The source.</param>
5856
public DFeCollection(IEnumerable<T> source)
59-
{
60-
List = source.ToList();
61-
}
57+
{
58+
AddRange(source);
59+
}
6260

6361
#endregion Constructors
6462

@@ -69,52 +67,42 @@ public DFeCollection(IEnumerable<T> source)
6967
/// </summary>
7068
/// <returns>T.</returns>
7169
public virtual T AddNew()
72-
{
73-
var item = (T)Activator.CreateInstance(typeof (T), true);
74-
List.Add(item);
75-
return item;
76-
}
70+
{
71+
var item = (T)Activator.CreateInstance(typeof(T), true);
72+
base.Add(item);
73+
return item;
74+
}
7775

7876
/// <summary>
7977
/// Adds the range.
8078
/// </summary>
8179
/// <param name="item">The item.</param>
82-
public virtual void Add(T item)
80+
public new virtual void Add(T item)
8381
{
84-
List.Add(item);
82+
base.Add(item);
8583
}
8684

8785
/// <summary>
8886
/// Adds the range.
8987
/// </summary>
9088
/// <param name="itens">The itens.</param>
91-
public virtual void AddRange(IEnumerable<T> itens)
92-
{
93-
List.AddRange(itens);
94-
}
89+
public new virtual void AddRange(IEnumerable<T> itens)
90+
{
91+
base.AddRange(itens);
92+
}
9593

9694
#endregion Methods
9795

9896
#region Operators
9997

100-
/// <summary>
101-
/// Performs an implicit conversion from <see cref="List{T}"/> to <see cref="DFeCollection{T}"/>.
102-
/// </summary>
103-
/// <param name="source">The source.</param>
104-
/// <returns>The result of the conversion.</returns>
105-
public static implicit operator DFeCollection<T>(List<T> source)
106-
{
107-
return new DFeCollection<T>(source);
108-
}
109-
11098
/// <summary>
11199
/// Performs an implicit conversion from <see cref="DFeCollection{T}"/> to <see cref="List{T}"/>.
112100
/// </summary>
113101
/// <param name="source">The source.</param>
114102
/// <returns>The result of the conversion.</returns>
115-
public static implicit operator List<T>(DFeCollection<T> source)
103+
public static implicit operator DFeCollection<T>(T[] source)
116104
{
117-
return source.List;
105+
return new DFeCollection<T>(source);
118106
}
119107

120108
#endregion Operators

src/ACBr.Net.DFe.Core/Serializer/DFeSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private XDocument Serialize(object item)
183183

184184
var rootElement = ObjectSerializer.Serialize(item, tipoDFe, rootName, Options);
185185
xmldoc.Add(rootElement);
186-
xmldoc.Root.RemoveEmptyNs();
186+
xmldoc.RemoveEmptyNs();
187187
return xmldoc;
188188
}
189189

src/ACBr.Net.DFe.Core/Serializer/ObjectType.cs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,13 @@ public static ObjectType From(object value)
5959

6060
public static ObjectType From(Type type)
6161
{
62-
if (IsPrimitive(type))
63-
return Primitive;
64-
if (IsDictionary(type))
65-
return Dictionary;
66-
if (IsList(type))
67-
return List;
68-
if (IsInterfaceObject(type))
69-
return InterfaceObject;
70-
if (IsRootObject(type))
71-
return RootObject;
72-
73-
return IsDFeList(type) ? DFeList : ClassObject;
62+
if (IsPrimitive(type)) return Primitive;
63+
if (IsInterfaceObject(type)) return InterfaceObject;
64+
if (IsRootObject(type)) return RootObject;
65+
if (IsDFeList(type)) return DFeList;
66+
if (IsDictionary(type)) return Dictionary;
67+
68+
return IsList(type) ? List : ClassObject;
7469
}
7570

7671
private int Id { get; }
@@ -95,11 +90,6 @@ public override int GetHashCode()
9590
return Id.GetHashCode();
9691
}
9792

98-
/// <summary>
99-
/// Checks if the type is a fundamental primitive object (e.g string, int etc.).
100-
/// </summary>
101-
/// <param name="type">The type to check.</param>
102-
/// <returns>The boolean value indicating whether the type is a fundamental primitive.</returns>
10393
private static bool IsPrimitive(Type type)
10494
{
10595
return type == typeof(string)
@@ -135,26 +125,17 @@ private static bool IsPrimitive(Type type)
135125
|| (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && type.GetGenericArguments()[0].IsEnum);
136126
}
137127

138-
/// <summary>
139-
/// Determines whether the specified type is list.
140-
/// </summary>
141-
/// <param name="type">The type.</param>
142-
/// <returns><c>true</c> if the specified type is list; otherwise, <c>false</c>.</returns>
143128
private static bool IsList(Type type)
144129
{
145-
return typeof(ICollection).IsAssignableFrom(type) ||
146-
(type.BaseType != null && typeof(ICollection).IsAssignableFrom(type.BaseType));
130+
return (typeof(ICollection).IsAssignableFrom(type) ||
131+
(type.BaseType != null && typeof(ICollection).IsAssignableFrom(type.BaseType))) &&
132+
!IsDFeList(type);
147133
}
148134

149-
/// <summary>
150-
/// Determines whether [is d fe list] [the specified type].
151-
/// </summary>
152-
/// <param name="type">The type.</param>
153-
/// <returns><c>true</c> if [is d fe list] [the specified type]; otherwise, <c>false</c>.</returns>
154135
private static bool IsDFeList(Type type)
155136
{
156137
return (type.IsGenericType && typeof(DFeCollection<>).IsAssignableFrom(type.GetGenericTypeDefinition())) ||
157-
(type.BaseType != null && type.BaseType.IsGenericType && typeof(DFeCollection<>).IsAssignableFrom(type.BaseType.GetGenericTypeDefinition()));
138+
(type.BaseType != null && type.BaseType.IsGenericType && typeof(DFeCollection<>).IsAssignableFrom(type.BaseType.GetGenericTypeDefinition()));
158139
}
159140

160141
private static bool IsInterfaceObject(Type type)
@@ -167,11 +148,6 @@ private static bool IsRootObject(Type type)
167148
return type.HasAttribute<DFeRootAttribute>();
168149
}
169150

170-
/// <summary>
171-
/// Determines whether the specified type is dictionary.
172-
/// </summary>
173-
/// <param name="type">The type.</param>
174-
/// <returns><c>true</c> if the specified type is dictionary; otherwise, <c>false</c>.</returns>
175151
public static bool IsDictionary(Type type)
176152
{
177153
return typeof(IDictionary).IsAssignableFrom(type);

src/ACBr.Net.DFe.Core/Serializer/PrimitiveSerializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ public static object Deserialize(IDFeElement tag, XObject parentElement, object
256256

257257
private static object GetValue(TipoCampo tipo, string valor, object item, PropertyInfo prop)
258258
{
259-
if (valor.IsEmpty())
260-
return null;
259+
if (valor.IsEmpty()) return null;
261260

262261
object ret;
263262
// ReSharper disable once SwitchStatementMissingSomeCases
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="ACBr.Net.Core" version="1.0.1.3-rc1" targetFramework="net40" />
3+
<package id="ACBr.Net.Core" version="1.0.1.3" targetFramework="net40" />
44
<package id="ExtraConstraints.Fody" version="1.10.9" targetFramework="net40" developmentDependency="true" />
55
<package id="Fody" version="1.29.4" targetFramework="net40" developmentDependency="true" />
66
</packages>

0 commit comments

Comments
 (0)