Beispiel #1
0
		public void CanMapOperation()
		{
			var mapper = new Mapper(new List<string> { "SecretThings" });

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			Assert.AreEqual(6, operations.Count());
			Assert.AreEqual("/method/test", operations.First().Item1);
			var operation = operations.First().Item2;

			Assert.AreEqual(3, operation.parameters.Count);

			var uno = operation.parameters.First(p => p.name.Equals("uno"));
			var dos = operation.parameters.First(p => p.name.Equals("dos"));
			var tres = operation.parameters.First(p => p.name.Equals("tRes"));

			Assert.AreEqual("query", uno.paramType);
			Assert.AreEqual(true, uno.required);
			Assert.IsTrue(string.IsNullOrEmpty(uno.description));

			Assert.AreEqual("query", dos.paramType);
			Assert.AreEqual(true, dos.required);
			Assert.AreEqual("integer(32)", dos.type);

			Assert.AreEqual("query", tres.paramType);
			Assert.AreEqual(false, tres.required);
			Assert.AreEqual("The third option.", tres.description);
			Assert.AreEqual("string(22)", tres.type);
		}
Beispiel #2
0
		public void CanMapOperationUriWithRequiredParams()
		{
			var mapper = new Mapper(new List<string> { "SecretThings" }, true, false);
			
			Assert.IsTrue(mapper.ShowRequiredQueryParamsInHeader);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			Assert.AreEqual("/method/test?uno={uno}&dos={dos}", operations.First().Item1);
		}
Beispiel #3
0
		public void CanMarkOperationSummaryIfTagged()
		{
			var mapper = new Mapper(null, false, true);
			Assert.IsTrue(mapper.MarkTagged);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			var operation = operations.First(o => o.Item1.Equals("/keepitsecret")).Item2;
			Assert.AreEqual("Secret method***", operation.summary);
		}
Beispiel #4
0
		public void CanMapDataTypeAsDataContractName()
		{
			var mapper = new Mapper(null);
			var map = typeof (MapTest).GetInterfaceMap(typeof (IMapTest));
			var testOperations = mapper.GetOperations(map, new Stack<Type>());
			var operation = testOperations.First(o => o.Item1.Equals("/customtypetest")).Item2;
			Assert.AreEqual("MyDataContractName", operation.type);
		}
Beispiel #5
0
		public void CanOverrideParameterTypeWithDataContractName()
		{
			var mapper = new Mapper(null);
			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var testOperations = mapper.GetOperations(map, new Stack<Type>());
			var operation = testOperations.First(o => o.Item1.Equals("/overrideparamtypeascustomtypetest")).Item2;
			Assert.AreEqual(1, operation.parameters.Count);
			Assert.AreEqual("MyRequest", GetTypeFromParamList("req", operation.parameters));
		}
Beispiel #6
0
		public void CanHideParameter()
		{
			var mapper = new Mapper(null);
			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());
			var operation = operations.First(o => o.Item1.Equals("/hideparamtest")).Item2;
			Assert.AreEqual(1, operation.parameters.Count);
			Assert.AreEqual("foo", operation.parameters[0].name);
			Assert.AreEqual("integer(32)", operation.parameters[0].type);
		}
Beispiel #7
0
		public void CanOverrideReturnType()
		{
			var mapper = new Mapper(null);
			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var realReturnType = map.InterfaceMethods.First(m => m.Name == "OverrideReturnTypeTest");
			Assert.IsNotNull(realReturnType);
			Assert.AreEqual(typeof(int), realReturnType.ReturnType);
			var operations = mapper.GetOperations(map, new Stack<Type>());
			var operation = operations.First(o => o.Item1.Equals("/overridereturntype")).Item2;
			Assert.AreEqual("string", operation.type);
		}
Beispiel #8
0
		public void CanMapVoidOperation()
		{
			var mapper = new Mapper(null);
			var map = typeof (MapTest).GetInterfaceMap(typeof (IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());
			var operation = operations.First(o => o.Item1.Equals("/voidtest")).Item2;
			Assert.IsNotNull(operation);
			Assert.AreEqual("None",operation.type);
		}
Beispiel #9
0
		public void CanMapBuiltInParams()
		{
			var mapper = new Mapper(null);
			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());
			var operation = operations.First(o => o.Item1.Equals("/voidtest")).Item2;

			Assert.AreEqual(17, operation.parameters.Count);
			Assert.AreEqual("boolean", GetTypeFromParamList("bl", operation.parameters));
			Assert.AreEqual("integer(8)", GetTypeFromParamList("bt", operation.parameters));
			Assert.AreEqual("integer(8, signed)", GetTypeFromParamList("sbt", operation.parameters));
			Assert.AreEqual("character", GetTypeFromParamList("ch", operation.parameters));
			Assert.AreEqual("decimal", GetTypeFromParamList("dm", operation.parameters));
			Assert.AreEqual("double", GetTypeFromParamList("db", operation.parameters));
			Assert.AreEqual("float", GetTypeFromParamList("fl", operation.parameters));
			Assert.AreEqual("integer(32)", GetTypeFromParamList("it", operation.parameters));
			Assert.AreEqual("integer(32, unsigned)", GetTypeFromParamList("uit", operation.parameters));
			Assert.AreEqual("integer(64)", GetTypeFromParamList("lg", operation.parameters));
			Assert.AreEqual("integer(64, unsigned)", GetTypeFromParamList("ulg", operation.parameters));
			Assert.AreEqual("integer(16)", GetTypeFromParamList("st", operation.parameters));
			Assert.AreEqual("integer(16, unsigned)", GetTypeFromParamList("ust", operation.parameters));
			Assert.AreEqual("string", GetTypeFromParamList("str", operation.parameters));
			Assert.AreEqual("Date", GetTypeFromParamList("dt", operation.parameters));
			Assert.AreEqual("string", GetTypeFromParamList("guid", operation.parameters));
			Assert.AreEqual("stream", GetTypeFromParamList("stream", operation.parameters));
			
		}
Beispiel #10
0
		public void CanMapNotesAndSummary()
		{
			var mapper = new Mapper(null);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());
			var operation = operations.First(o => o.Item1.Equals("/method/test")).Item2;

			Assert.AreEqual("Short format", operation.summary);
			Assert.AreEqual("Long format", operation.notes);
		}
Beispiel #11
0
		public void CanMapContentTypes()
		{
			var mapper = new Mapper(null);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			var operation = operations.First(o => o.Item1.Equals("/keepitsecret")).Item2;
			Assert.AreEqual(1, operation.produces.Count);
			Assert.AreEqual("application/xml", operation.produces[0]);

			var operation2 = operations.First(o => o.Item1.Equals("/method/test")).Item2;
			Assert.AreEqual(2, operation2.produces.Count);
			Assert.IsTrue(operation2.produces.Contains("application/xml"));
			Assert.IsTrue(operation2.produces.Contains("application/json"));
		}
Beispiel #12
0
		[TestMethod]public void CanSortResponseCodes()
		{
			var mapper = new Mapper(null);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			var operation = operations.First(o => o.Item1.Equals("/keepitsecret")).Item2;

			Assert.AreEqual(7, operation.errorResponses.Count());

			var lastIndex = operation.errorResponses.Count() - 1;
			for (int i = 0; i < lastIndex; i++)
			{
				if (i == (lastIndex - 1))
					break;
				Assert.IsTrue(operation.errorResponses[i].code < operation.errorResponses[i + 1].code);
			}
		}
Beispiel #13
0
		public void CanMapResponseCodes()
		{
			var mapper = new Mapper(null);

			var map = typeof(MapTest).GetInterfaceMap(typeof(IMapTest));
			var operations = mapper.GetOperations(map, new Stack<Type>());

			var operation = operations.First(o => o.Item1.Equals("/keepitsecret")).Item2;

			Assert.AreEqual(7, operation.errorResponses.Count());
			Assert.AreEqual("OK", operation.errorResponses[0].message);
			Assert.AreEqual(200, operation.errorResponses[0].code);
		}
Beispiel #14
0
        private static void BuildPaths(Service service, IList<string> hiddenTags, IList<Type> definitionsTypesList)
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            service.Paths = new List<Path>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable<TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    var da = ti.GetCustomAttribute<SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                        continue;

                    var mapper = new Mapper(hiddenTags);

                    IEnumerable<Path> paths = mapper.FindMethods(da.ServicePath, ti.AsType(), definitionsTypesList);
                    service.Paths.AddRange(paths);
                }
            }
        }