示例#1
0
        public async Task NotReturnCategoryOfmCollection_WhenResourceParametersAreInvalid()
        {
            // Arrange
            var asyncDataCrudMock = new Mock <IAsyncCrud <Category, int, CategoryResourceParameters> >();

            asyncDataCrudMock
            .Setup(s => s.GetPagedCollection(It.IsAny <CategoryResourceParameters>())).Returns(Task.FromResult(new PagedList <Category>(
                                                                                                                   new List <Category>()
            {
                new Category()
                {
                    Id        = 1,
                    Name      = "MockCategory1",
                    OwnerGuid = _ownerGuid
                },
                new Category()
                {
                    Id        = 2,
                    Name      = "MockCategory2",
                    OwnerGuid = _ownerGuid
                }
            }, 1000, 2, 100)
                                                                                                               ));

            var categoryOfmRepository = new CategoryOfmRepository(asyncDataCrudMock.Object, new PropertyMappingService(), new TypeHelperService());

            // Act
            var categoryOfmCollectionQueryResult = await categoryOfmRepository.GetCollection(new CategoryOfmCollectionResourceParameters()
            {
                Fields  = "ThisFieldDoesntExistOnCategory",
                OrderBy = "ThisFieldDoesntExistOnCategory",
                Ids     = "TheseIds ,5-,99, are incorrect"
            }, _ownerGuid);

            // Assert
            var actualCategoryOfmCollectionQueryResult = JsonConvert.SerializeObject(categoryOfmCollectionQueryResult,
                                                                                     new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented
            });

            var expectedOfmForGetCollectionQueryResult = JsonConvert.SerializeObject(
                new OfmForGetCollectionQueryResult <CategoryOfmForGet>()
            {
                ReturnedTOfmForGetCollection = new OfmForGetCollection <CategoryOfmForGet>()
                {
                    OfmForGets = null
                },
                ErrorMessages = new List <string>()
                {
                    "Your concatenated range of integer ids is badly formatted. It must meet the regular expression '(^([1-9]{1}d*(-[1-9]{1}d*)?((,[1-9]{1}d*)?(-[1-9]{1}d*)?)*|null)$)|(^$)'",
                    "The range of integer ids is invalid or not in an ascending order. For example, '10-8,7,6-1' is not in an ascending order and should be '1-6,7,8-10' instead",
                    "A property named 'ThisFieldDoesntExistOnCategory' does not exist"
                },
                CurrentPage = 0,
                TotalPages  = 0,
                PageSize    = 0,
                TotalCount  = 0
            },
                new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented
            });

            Assert.AreEqual(expectedOfmForGetCollectionQueryResult, actualCategoryOfmCollectionQueryResult);
        }
示例#2
0
        public async Task ReturnCorrectCategoryOfmCollectionQueryResult()
        {
            // Arrange
            var asyncDataCrudMock = new Mock <IAsyncCrud <Category, int, CategoryResourceParameters> >();

            asyncDataCrudMock
            .Setup(s => s.GetPagedCollection(It.IsAny <CategoryResourceParameters>())).Returns(Task.FromResult(new PagedList <Category>(
                                                                                                                   new List <Category>()
            {
                new Category()
                {
                    Id        = 1,
                    Name      = "MockCategory1",
                    OwnerGuid = _ownerGuid
                },
                new Category()
                {
                    Id        = 2,
                    Name      = "MockCategory2",
                    OwnerGuid = _ownerGuid
                }
            }, 1000, 2, 100)
                                                                                                               ));

            var categoryOfmRepository = new CategoryOfmRepository(asyncDataCrudMock.Object, new PropertyMappingService(), new TypeHelperService());

            // Act
            var categoryOfmCollectionQueryResult = await categoryOfmRepository.GetCollection(new CategoryOfmCollectionResourceParameters(), _ownerGuid);

            // Assert
            var actualCategoryOfmCollectionQueryResult = JsonConvert.SerializeObject(categoryOfmCollectionQueryResult,
                                                                                     new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented
            });

            var expectedOfmForGetCollectionQueryResult = JsonConvert.SerializeObject(
                new OfmForGetCollectionQueryResult <CategoryOfmForGet>()
            {
                ReturnedTOfmForGetCollection = new OfmForGetCollection <CategoryOfmForGet>()
                {
                    OfmForGets = new List <CategoryOfmForGet>()
                    {
                        new CategoryOfmForGet()
                        {
                            Id   = 1,
                            Name = "MockCategory1"
                        },
                        new CategoryOfmForGet()
                        {
                            Id   = 2,
                            Name = "MockCategory2"
                        }
                    }
                },
                ErrorMessages = new List <string>(),
                CurrentPage   = 2,
                TotalPages    = 10,
                PageSize      = 100,
                TotalCount    = 1000
            },
                new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented
            });

            Assert.AreEqual(expectedOfmForGetCollectionQueryResult, actualCategoryOfmCollectionQueryResult);
        }