Skip to content

Commit

Permalink
Merge pull request #506 from DigDes/develop
Browse files Browse the repository at this point in the history
v1.1.0.2-alpha
  • Loading branch information
kotovaleksandr authored Jul 20, 2020
2 parents a161292 + 15c0ceb commit 3c1f875
Show file tree
Hide file tree
Showing 27 changed files with 1,069 additions and 92 deletions.
21 changes: 21 additions & 0 deletions src/SoapCore.Tests/ITestService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.ServiceModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -66,5 +67,25 @@ public interface ITestService

[OperationContract]
string PingWithServiceOperationTuning();

[OperationContract]
ComplexModelInput[] ArrayOfComplexItems(ComplexModelInput[] items);

[OperationContract]
List<ComplexModelInput> ListOfComplexItems(List<ComplexModelInput> items);

[OperationContract]
Dictionary<string, string> ListOfDictionaryItems(Dictionary<string, string> items);

[OperationContract]
ComplexInheritanceModelInputBase GetComplexInheritanceModel(ComplexInheritanceModelInputBase input);

[ServiceKnownType(typeof(ComplexModelInput))]
[OperationContract]
ComplexModelInput ComplexModelInputFromServiceKnownType(object value);

[ServiceKnownType(typeof(ComplexModelInput))]
[OperationContract]
object ObjectFromServiceKnownType(ComplexModelInput value);
}
}
73 changes: 72 additions & 1 deletion src/SoapCore.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -133,6 +133,77 @@ public void RefParam()
Assert.AreEqual("hello, world", message);
}

[TestMethod]
public void ArrayInput()
{
var client = CreateClient();
List<ComplexModelInput> complexModelInputs = new List<ComplexModelInput>();
complexModelInputs.Add(new ComplexModelInput());
var e = client.ArrayOfComplexItems(complexModelInputs.ToArray());
Assert.AreEqual(e.Length, complexModelInputs.Count);
}

[TestMethod]
public void ListInput()
{
var client = CreateClient();
List<ComplexModelInput> complexModelInputs = new List<ComplexModelInput>();
complexModelInputs.Add(new ComplexModelInput());
var e = client.ListOfComplexItems(complexModelInputs);
Assert.AreEqual(e.Count, complexModelInputs.Count);
}

[TestMethod]
public void DictionaryInput()
{
var client = CreateClient();
Dictionary<string, string> dictionaryInputs = new Dictionary<string, string>();
dictionaryInputs.Add("1", "2");
var e = client.ListOfDictionaryItems(dictionaryInputs);
Assert.AreEqual(e["1"], dictionaryInputs["1"]);
Assert.AreEqual(e.Count, dictionaryInputs.Count);
}

[TestMethod]
[DataRow(typeof(ComplexInheritanceModelInputA))]
[DataRow(typeof(ComplexInheritanceModelInputB))]
public void GetComplexInheritanceModel(Type type)
{
var client = CreateClient();
var input = (ComplexInheritanceModelInputBase)Activator.CreateInstance(type);
var output = client.GetComplexInheritanceModel(input);
Assert.AreEqual(input.GetType(), output.GetType());
}

[TestMethod]
public void ComplexModelInputFromServiceKnownType()
{
var client = CreateClient();
var input = new ComplexModelInput
{
IntProperty = 123,
StringProperty = "Test string",
};
var output = client.ComplexModelInputFromServiceKnownType(input);
Assert.AreEqual(input.IntProperty, output.IntProperty);
Assert.AreEqual(input.StringProperty, output.StringProperty);
}

[TestMethod]
public void ObjectFromServiceKnownType()
{
var client = CreateClient();
var input = new ComplexModelInput
{
IntProperty = 123,
StringProperty = "Test string",
};
var output = client.ObjectFromServiceKnownType(input);
Assert.IsInstanceOfType(output, typeof(ComplexModelInput));
Assert.AreEqual(input.IntProperty, ((ComplexModelInput)output).IntProperty);
Assert.AreEqual(input.StringProperty, ((ComplexModelInput)output).StringProperty);
}

[TestMethod]
public void ThrowsFaultException()
{
Expand Down
12 changes: 12 additions & 0 deletions src/SoapCore.Tests/Model/ComplexInheritanceModelInputA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.Serialization;

namespace SoapCore.Tests.Model
{
[KnownType(typeof(ComplexInheritanceModelInputB))]
[DataContract(Name = "ComplexInheritanceModelInputA")]
public class ComplexInheritanceModelInputA : ComplexInheritanceModelInputBase
{
[DataMember]
public override string Example { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/SoapCore.Tests/Model/ComplexInheritanceModelInputB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.Serialization;

namespace SoapCore.Tests.Model
{
[DataContract(Name = "ComplexInheritanceModelInputB")]
public class ComplexInheritanceModelInputB : ComplexInheritanceModelInputA
{
[DataMember]
public int Example2 { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/SoapCore.Tests/Model/ComplexInheritanceModelInputBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.Serialization;

namespace SoapCore.Tests.Model
{
[KnownType(typeof(ComplexInheritanceModelInputA))]
[KnownType(typeof(ComplexInheritanceModelInputB))]
[DataContract(Name = "ComplexInheritanceModelInputBase")]
public abstract class ComplexInheritanceModelInputBase
{
[DataMember]
public string StringProperty { get; set; }

[DataMember]
public abstract string Example { get; set; }
}
}
61 changes: 61 additions & 0 deletions src/SoapCore.Tests/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,66 @@ public string PingWithServiceOperationTuning()
{
return _pingResultValue.Value;
}

public ComplexModelInput[] ArrayOfComplexItems(ComplexModelInput[] items)
{
return items;
}

public List<ComplexModelInput> ListOfComplexItems(List<ComplexModelInput> items)
{
return items;
}

public Dictionary<string, string> ListOfDictionaryItems(Dictionary<string, string> items)
{
return items;
}

public ComplexInheritanceModelInputBase GetComplexInheritanceModel(ComplexInheritanceModelInputBase input)
{
switch (input)
{
case ComplexInheritanceModelInputB _:
{
return new ComplexInheritanceModelInputB();
}

case ComplexInheritanceModelInputA _:
{
return new ComplexInheritanceModelInputA();
}

default:
{
throw new NotImplementedException();
}
}
}

public ComplexModelInput ComplexModelInputFromServiceKnownType(object value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}

if (value is ComplexModelInput input)
{
return input;
}

throw new Exception($"Invalid object type `{value.GetType()}`.");
}

public object ObjectFromServiceKnownType(ComplexModelInput value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}

return value;
}
}
}
10 changes: 10 additions & 0 deletions src/SoapCore.Tests/Wsdl/Services/CustomDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SoapCore.Tests.Wsdl.Services
{
public class CustomDictionary : Dictionary<string, string>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace SoapCore.Tests.Wsdl.Services
{
[ServiceKnownType(typeof(AnonymousServiceKnownTypesService.Dog))]
[ServiceContract]
public interface IAnonymousServiceKnownTypesService
{
[ServiceKnownType(typeof(AnonymousServiceKnownTypesService.Cat))]
[OperationContract]
object TestFromTypedToAny(AnonymousServiceKnownTypesService.Animal value);

[ServiceKnownType(typeof(AnonymousServiceKnownTypesService.Squirrel))]
[OperationContract]
AnonymousServiceKnownTypesService.Animal TestFromAnyToTyped(object value);
}

public class AnonymousServiceKnownTypesService : IAnonymousServiceKnownTypesService
{
public object TestFromTypedToAny(Animal value)
{
return value;
}

public Animal TestFromAnyToTyped(object value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}

if (value is Animal result)
{
return result;
}

throw new Exception($"Object of type `{value.GetType()}` is not supported in this context.");
}

[DataContract(Name = "Animal")]
public class Animal
{
}

[DataContract(Name = "Dog")]
public class Dog : Animal
{
}

[DataContract(Name = "Cat")]
public class Cat : Animal
{
}

[DataContract(Name = "Squirrel")]
public class Squirrel : Animal
{
}
}
}
27 changes: 27 additions & 0 deletions src/SoapCore.Tests/Wsdl/Services/IDictionaryTypeListService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ServiceModel;
using SoapCore.Tests.Model;

namespace SoapCore.Tests.Wsdl.Services
{
[ServiceContract]
public interface IDictionaryTypeListService
{
[OperationContract]
List<ComplexModelInput> Test();

[OperationContract]
Dictionary<string, string> DictionaryTest(Dictionary<string, string> thing);
}

public class DictionaryTypeListService : IDictionaryTypeListService
{
public Dictionary<string, string> DictionaryTest(Dictionary<string, string> thing)
{
throw new NotImplementedException();
}

public List<ComplexModelInput> Test() => throw new NotImplementedException();
}
}
36 changes: 36 additions & 0 deletions src/SoapCore.Tests/Wsdl/Services/IInheritanceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Runtime.Serialization;
using System.ServiceModel;

namespace SoapCore.Tests.Wsdl.Services
{
[ServiceContract]
public interface IInheritanceService
{
[OperationContract]
InheritanceService.Animal Test();
}

public class InheritanceService : IInheritanceService
{
public Animal Test()
{
return new Dog
{
Name = "Test",
};
}

[KnownType(typeof(Dog))]
[DataContract(Name = "Animal")]
public abstract class Animal
{
[DataMember]
public string Name { get; set; }
}

[DataContract(Name = "Dog")]
public class Dog : Animal
{
}
}
}
Loading

0 comments on commit 3c1f875

Please sign in to comment.