예제 #1
0
        public async Task UpdateHiveAsync_SuccessfulTest(int id, string name, string code, string address)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "11111"
                }
            });
            var service = new HiveService(context.Object, userContext.Object);
            var request = new UpdateHiveRequest
            {
                Name    = name,
                Code    = code,
                Address = address
            };

            await service.UpdateHiveAsync(id, request);

            var actualHive = await service.GetHiveAsync(id);

            Assert.Equal(code, actualHive.Code);
        }
예제 #2
0
        public async Task UpdateHiveAsync_ChangeHiveProperties_UpdatedHiveReturned()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHive()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var service = new HiveService(context.Object, new UserContext());
            var request = new UpdateHiveRequest {
                Code = "CODE3", Name = "New Name", Address = "New Address"
            };

            var hive = await service.UpdateHiveAsync(1, request);

            Assert.Equal(request.Code, hive.Code);
            Assert.Equal(request.Name, hive.Name);
            Assert.Equal(request.Address, hive.Address);
        }
예제 #3
0
        public async Task UpdateHiveAsync_ValidRequest_HiveUpdated()
        {
            var newHive = new UpdateHiveRequest()
            {
                Code = "cc"
            };
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHive()
                {
                    Id = 2, Code = "bb"
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            var service = new HiveService(mockHiveContext.Object, mockUserContext.Object);

            var updatedHive = await service.UpdateHiveAsync(1, newHive);

            Assert.Equal(newHive.Code, updatedHive.Code);
        }
예제 #4
0
        public async Task UpdateHiveAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown()
        {
            var newHive = new UpdateHiveRequest()
            {
                Code = "bb"
            };
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHive()
                {
                    Id = 2, Code = "bb"
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            var service = new HiveService(mockHiveContext.Object, mockUserContext.Object);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveAsync(3, newHive));
        }
예제 #5
0
        public async Task UpdateHiveAsync_ChangeCodeToExistingHiveCode_ExceptionThrown()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHive()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var service = new HiveService(context.Object, new UserContext());
            var request = new UpdateHiveRequest {
                Code = "CODE1"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() =>
            {
                await service.UpdateHiveAsync(1, request);
            });
        }
        public async void UpdateHiveAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveRequest = fixture.Create <UpdateHiveRequest>();
            int id = 0;

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveAsync(id, updateHiveRequest));
        }
예제 #7
0
        public async Task UpdateHiveAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            context.Setup(s => s.Hives).ReturnsEntitySet(new StoreHive[] { });

            var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.UpdateHiveAsync(0, fixture.Create <UpdateHiveRequest>()));

            Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType());
        }
        public async void UpdateHiveAsync_EntityWithExistedCode_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveRequest = fixture.Create <UpdateHiveRequest>();

            updateHiveRequest.Code = _hive[0].Code;
            int id = _hive[1].Id;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.UpdateHiveAsync(id, updateHiveRequest));
        }
예제 #9
0
        public async Task UpdateHiveTestAsync_AcceptsMatchCodeAndMismatchId_ThrowsException([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId        = 1;
            var updateRequest = fixture.Create <UpdateHiveRequest>();
            var hives         = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id   = 2;
            hives[0].Code = updateRequest.Code;
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.UpdateHiveAsync(hiveId, updateRequest));
        }
        public async void UpdateHiveAsync_ValidEntity_SuccessfullHiveEdition([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveRequest = fixture.Create <UpdateHiveRequest>();
            int id = _hive[0].Id;

            var result = await service.UpdateHiveAsync(id, updateHiveRequest);

            result.Id.Should().Be(id);
            result.Code.Should().Be(updateHiveRequest.Code);
            result.Name.Should().Be(updateHiveRequest.Name);
            result.Address.Should().Be(updateHiveRequest.Address);
        }
예제 #11
0
        public async Task UpdateHiveAsync_UpdateNonExistentHive_ExceptionThrown()
        {
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, new UserContext());
            var request = new UpdateHiveRequest();

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() =>
            {
                await service.UpdateHiveAsync(0, request);
            });
        }
        public async Task UpdateHive_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToArray();

            contex.Setup(x => x.Hives).ReturnsEntitySet(collection);
            var hive = fixture.Create <UpdateHiveRequest>();

            Func <Task> act = async() => await service.UpdateHiveAsync(1, hive);

            act.Should().Throw <RequestedResourceNotFoundException>();
        }
예제 #13
0
        public async Task UpdateHiveTestAsync_ReturnsUpdatedHive([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId        = 1;
            var updateRequest = fixture.Create <UpdateHiveRequest>();
            var hives         = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id   = hiveId;
            hives[0].Code = updateRequest.Code + "new code info";
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            var updateHive = await service.UpdateHiveAsync(hiveId, updateRequest);

            Assert.Equal(updateRequest.Name, updateHive.Name);
            Assert.Equal(updateRequest.Code, updateHive.Code);
        }
예제 #14
0
        public async Task UpdateHiveAsync_ChangeHiveProperties_UpdatedHiveReturned([Frozen] Mock <IProductStoreHiveContext> context, UpdateHiveRequest request, HiveService service, IFixture fixture)
        {
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var hives = fixture.CreateMany <StoreHive>(2).ToArray();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);

            var hive = await service.UpdateHiveAsync(hives[1].Id, request);

            Assert.Equal(request.Code, hive.Code);
            Assert.Equal(request.Name, hive.Name);
            Assert.Equal(request.Address, hive.Address);
        }
예제 #15
0
        public async Task UpdateHive_UpdateSuccessfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity = fixture.CreateMany <StoreHive>(13).ToList();

            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            var createRequest = fixture.Create <UpdateHiveRequest>();
            var addedHive     = await hiveService.UpdateHiveAsync(listEntity[0].Id, createRequest);

            var hive = await hiveService.GetHiveAsync(addedHive.Id);

            Assert.Equal(hive.Id, listEntity[0].Id);
            Assert.Equal(hive.Name, createRequest.Name);
            Assert.Equal(hive.Address, createRequest.Address);
            Assert.Equal(hive.Code, createRequest.Code);
        }
예제 #16
0
        public void UpdateHiveAsync_NoHiveWithSuchIdTest(int id, string name, string code, string address)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, userContext.Object);
            var request = new UpdateHiveRequest
            {
                Name    = name,
                Code    = code,
                Address = address
            };

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.UpdateHiveAsync(id, request));
        }
예제 #17
0
        public async Task UpdateHiveAsync_PassesHiveIdAndUpdateHiveRequest_ExpectsRequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            var createRequest = new UpdateHiveRequest {
                Address = "Kuprevicha 1-1", Code = "12345", Name = "qwerty"
            };

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => hiveService.UpdateHiveAsync(123, createRequest));
        }
        public async Task UpdateHive_SetFive_OneUpdate(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(collection);
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var name       = "New Name";
            var updateHive = new UpdateHiveRequest {
                Name = name
            };
            var result = await service.UpdateHiveAsync(collection[0].Id, updateHive);

            result.Code.Should().Be(collection[0].Code);
            result.Name.Should().Be(name);
        }
예제 #19
0
        public async Task UpdateHiveAsync_UpdateRequestAsParametr_NotExistedHiveId_ThrowException()
        {
            var updateReq = new UpdateHiveRequest()
            {
                Name    = "UpdateName",
                Code    = "TEST2",
                Address = "string"
            };

            var hiveId = 10;

            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives);

            var service = new HiveService(storeContext.Object, userContext.Object);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveAsync(hiveId, updateReq));
        }
예제 #20
0
        public async Task UpdateHiveAsync_HiveId_UpdateHiveRequest_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var hiveId = 1;

            var dbUpdateHiveRequest = fixture.Create <UpdateHiveRequest>();

            var dbHives = fixture.CreateMany <StoreHive>(1).ToList();

            dbHives[0].Id = hiveId + 1;

            dbHives[0].Code = $"{dbUpdateHiveRequest.Code}1";

            context.Setup(s => s.Hives).ReturnsEntitySet(dbHives);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.UpdateHiveAsync(hiveId, dbUpdateHiveRequest));
        }
예제 #21
0
        public async Task UpdateHive_TryUpdateHive_UpdatedHiveReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var existedhive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = "newCode"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { existedhive });

            var updatedHive = await service.UpdateHiveAsync(existedhive.Id, newHive);

            Assert.True(updatedHive.Code == newHive.Code);
        }
예제 #22
0
        public async void UpdateHiveSuccessfull()
        {
            var productContext = new Mock <IProductStoreHiveContext>();

            productContext.Setup(p => p.Hives).ReturnsEntitySet(new List <StoreHive>());

            var userContext = new Mock <IUserContext>();

            userContext.Setup(u => u.UserId).Returns(1);

            var service = new HiveService(productContext.Object, userContext.Object);

            var updateRequest = new UpdateHiveRequest
            {
                Address = "address",
                Code    = "11",
                Name    = "name"
            };

            await service.UpdateHiveAsync(1, updateRequest);
        }
예제 #23
0
        public async Task UpdateHiveAsync_UpdateRequestAsParametr_ReturnedUpdatedElement()
        {
            var updateReq = new UpdateHiveRequest()
            {
                Name    = "UpdateName",
                Code    = "TEST1",
                Address = "string"
            };

            var hiveId = 1;

            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives);

            var service = new HiveService(storeContext.Object, userContext.Object);
            var hive    = await service.UpdateHiveAsync(hiveId, updateReq);

            Assert.Equal(updateReq.Name, hive.Name);
            Assert.Equal(updateReq.Code, hive.Code);
            Assert.Equal(updateReq.Address, hive.Address);
        }
예제 #24
0
        public async Task UpdateHiveAsync_HiveId_UpdateHiveRequest_Success(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var hiveId = 1;

            var dbUpdateHiveRequest = fixture.Create <UpdateHiveRequest>();

            var dbHives = fixture.CreateMany <StoreHive>(1).ToList();

            dbHives[0].Id = hiveId;

            dbHives[0].Code = $"{dbUpdateHiveRequest.Code} + 1";

            context.Setup(s => s.Hives).ReturnsEntitySet(dbHives);

            var updateHive = await service.UpdateHiveAsync(hiveId, dbUpdateHiveRequest);

            Assert.Equal(dbUpdateHiveRequest.Name, updateHive.Name);
            Assert.Equal(dbUpdateHiveRequest.Address, updateHive.Address);
            Assert.Equal(dbUpdateHiveRequest.Code, updateHive.Code);
        }
예제 #25
0
        public async Task UpdateHiveAsync_PassesHiveIdAndUpdateHiveRequest_ExpectsSuccessfullEqualityAssertion(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToArray();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            var createRequest = new UpdateHiveRequest {
                Address = "Kuprevicha 1-1", Code = "12345", Name = "qwerty"
            };

            var expectedHive = await hiveService.UpdateHiveAsync(storeHives[1].Id, createRequest);

            var actualHive = await hiveService.GetHiveAsync(expectedHive.Id);

            Assert.Equal(expectedHive.Id, actualHive.Id);
            Assert.Equal(expectedHive.Name, actualHive.Name);
            Assert.Equal(expectedHive.Address, actualHive.Address);
            Assert.Equal(expectedHive.Code, actualHive.Code);
            Assert.Equal(expectedHive.IsDeleted, actualHive.IsDeleted);
        }
예제 #26
0
        public async Task DeleteHive_NotFoundException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService, int hiveId)
        {
            var listEntity    = fixture.CreateMany <StoreHive>(13).ToList();
            var createRequest = fixture.Create <UpdateHiveRequest>();

            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveService.UpdateHiveAsync(hiveId, createRequest));

            Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType());
        }
예제 #27
0
        public async Task UpdateHive_UpdateWithUnExistedId_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.UpdateHiveAsync(1, new UpdateHiveRequest()));
        }
예제 #28
0
        public async Task UpdateHive_UpdateHiveToExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var existedhive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var updatedExistedHive = new StoreHive
            {
                Id   = 2,
                Code = "Code1"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = "Code"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { existedhive, updatedExistedHive });

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.UpdateHiveAsync(2, newHive));
        }
예제 #29
0
        public void UpdateHiveAsync_SuchHiveCodeAlreadyExistsTest(int id, string name, string code, string address)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "11111"
                }
            });
            var service = new HiveService(context.Object, userContext.Object);
            var request = new UpdateHiveRequest
            {
                Name    = name,
                Code    = code,
                Address = address
            };

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.UpdateHiveAsync(id, request));
        }