Пример #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));
        }