Пример #1
0
        public override IEnumerable <object[]> GetData(MethodInfo testMethod)
        {
            // Guid and DateTime values shared for serialization test
            var sharedGuid     = Guid.Parse("96685bc4-dcb7-4b22-90cc-ca83baff8186");
            var sharedDateTime = DateTime.Parse("Fri, 1 May 2020 00:00:00Z");

            // dummies
            var emptyLink = new ResourceLink("", "", "");
            var testee    = new Testee {
                Id = sharedGuid, CreatedDate = sharedDateTime
            };
            var nestedTestee = new NestedTestee
            {
                Id          = sharedGuid,
                CreatedDate = sharedDateTime,
                Nested      = testee,
                Collection  = new List <Testee> {
                    testee
                }
            };
            var genericTestee = new GenericTestee <Testee>
            {
                Nested      = nestedTestee,
                Id          = sharedGuid,
                CreatedDate = sharedDateTime,
                Collection  = new List <Testee> {
                    testee, nestedTestee
                }
            };
            var testeeList = new List <Testee> {
                testee, nestedTestee, genericTestee
            };
            var testeePagination = new Pagination <Testee>(testeeList, testeeList.Count, 5);

            // resources
            var resources = testeeList.Select(x =>
            {
                var resource = new SingleResource(x);
                resource.Links.Add(emptyLink);
                return(resource);
            }).ToList();

            var enumerableResource = new EnumerableResource(resources);

            enumerableResource.Links.Add(emptyLink);
            var paginationResource = new PaginationResource(resources, resources.Count(), 5, 1);

            paginationResource.Links.Add(emptyLink);

            // expectedOutputs
            var expectedSingleString     = File.ReadAllText(Path.Combine("Serialization", "SingleResource.json"));
            var expectedEnumerableString = File.ReadAllText(Path.Combine("Serialization", "EnumerableResource.json"));
            var expectedPaginationString = File.ReadAllText(Path.Combine("Serialization", "PaginationResource.json"));

            yield return(new object[] { testee, resources.First(), expectedSingleString });

            yield return(new object[] { testeeList, enumerableResource, expectedEnumerableString });

            yield return(new object[] { testeePagination, paginationResource, expectedPaginationString });
        }
Пример #2
0
        public PaginationResource Create(IPagination source, Type type)
        {
            var singleResources    = ToEnumerableOfResources(source.GetItems(), type);
            var paginationResource = new PaginationResource(singleResources, source.Count, source.PageSize, source.Page);

            BuildResourceLinks(paginationResource, source, type);
            return(paginationResource);
        }
        public override IEnumerable <object[]> GetData(MethodInfo testMethod)
        {
            var testee     = new Testee();
            var listTestee = new List <Testee> {
                testee
            };
            var paginationTestee = new Pagination <Testee>(listTestee, 1, 10);

            var singleResources     = listTestee.Select(x => new SingleResource(x)).ToList();
            var enumerableResource  = new EnumerableResource(singleResources);
            var paginationResources = new PaginationResource(singleResources, 1, 10, 1);

            yield return(new object[] { new SingleResource(testee), testee, typeof(Testee) });                         //,(Testee) null};

            yield return(new object[] { enumerableResource, listTestee, typeof(List <Testee>) });                      //, testee};

            yield return(new object[] { paginationResources, paginationTestee, typeof(Pagination <Testee>) });         //, testee};
        }