public async Task UpdateHiveSectionAsync_ValidRequest_HiveUpdated() { var newHiveSection = new UpdateHiveSectionRequest() { Code = "cc" }; var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, Code = "aa" }, new StoreHiveSection() { Id = 2, Code = "bb" } }; mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(hiveSectionsList); var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object); var updatedHiveSection = await service.UpdateHiveSectionAsync(1, newHiveSection); Assert.Equal(newHiveSection.Code, updatedHiveSection.Code); }
public async Task UpdateHiveSectionAsync_SuccessfulTest(int id, string name, string code) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, Code = "11111" }, new StoreHiveSection() { Id = 2, Code = "11112" } }); var service = new HiveSectionService(context.Object, userContext.Object); var request = new UpdateHiveSectionRequest { Name = name, Code = code, }; await service.UpdateHiveSectionAsync(id, request); var actualHive = await service.GetHiveSectionAsync(id); Assert.Equal(code, actualHive.Code); }
public async Task UpdateHiveSectionAsync_ChangeCodeToExistingSectionCode_ExceptionThrown() { var sections = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 0, Code = "CODE1" }, new StoreHiveSection() { Id = 1, Code = "CODE2" } }; var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(sections); var service = new HiveSectionService(context.Object, new UserContext()); var request = new UpdateHiveSectionRequest { Code = "CODE1" }; await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => { await service.UpdateHiveSectionAsync(1, request); }); }
public async Task UpdateHiveSectionAsync_ChangeSectionProperties_UpdatedSectionReturned() { var sections = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 0, Code = "CODE1" }, new StoreHiveSection() { Id = 1, Code = "CODE2" } }; var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(sections); var service = new HiveSectionService(context.Object, new UserContext()); var request = new UpdateHiveSectionRequest { Code = "CODE3", Name = "New Name" }; var section = await service.UpdateHiveSectionAsync(1, request); Assert.Equal(request.Code, section.Code); Assert.Equal(request.Name, section.Name); }
public void UpdateHiveSectionAsync_NoHiveWithSuchIdTest(int id, string name, string code) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, Code = "11111" }, new StoreHiveSection() { Id = 2, Code = "11112" } }); var service = new HiveSectionService(context.Object, userContext.Object); var request = new UpdateHiveSectionRequest { Name = name, Code = code, }; Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.UpdateHiveSectionAsync(id, request)); }
public async Task UpdateHiveSectionAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var newHiveSection = new UpdateHiveSectionRequest() { Code = "aa" }; var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, Code = "aa" }, new StoreHiveSection() { Id = 2, Code = "bb" } }; mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(hiveSectionsList); var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveSectionAsync(3, newHiveSection)); }
public async void UpdateHiveSectionAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); var updateHiveSectionRequest = fixture.Create <UpdateHiveSectionRequest>(); int id = 0; await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveSectionAsync(id, updateHiveSectionRequest)); }
public async Task UpdateHiveSectionAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { context.Setup(s => s.Sections).ReturnsEntitySet(new StoreHiveSection[] { }); var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.UpdateHiveSectionAsync(0, fixture.Create <UpdateHiveSectionRequest>())); Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType()); }
public async void UpdateHiveSectionAsync_ValidEntity_SuccessfullHiveEdition([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); var updateHiveSectionRequest = fixture.Create <UpdateHiveSectionRequest>(); int id = _section[0].Id; var result = await service.UpdateHiveSectionAsync(id, updateHiveSectionRequest); result.Id.Should().Be(id); result.Code.Should().Be(updateHiveSectionRequest.Code); result.Name.Should().Be(updateHiveSectionRequest.Name); }
public async Task UpdateHiveSectionAsync_UpdateNonExistentSection_ExceptionThrown() { var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); var service = new HiveSectionService(context.Object, new UserContext()); var request = new UpdateHiveSectionRequest(); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => { await service.UpdateHiveSectionAsync(0, request); }); }
public async Task UpdateHiveSection_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contex, HiveSectionService service, IFixture fixture) { var hiveSection = fixture.CreateMany <StoreHiveSection>(5).ToList(); var hive = fixture.CreateMany <StoreHive>(3).ToArray(); contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSection); contex.Setup(x => x.Hives).ReturnsEntitySet(hive); var hiveSectionUpdate = fixture.Create <UpdateHiveSectionRequest>(); Func <Task> act = async() => await service.UpdateHiveSectionAsync(200, hiveSectionUpdate); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task UpdateHiveAsync_PassesHiveIdAndUpdateHiveRequest_ExpectsRequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, 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 UpdateHiveSectionRequest { Code = "12345", Name = "qwerty", HiveId = 123 }; await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => hiveSectionService.UpdateHiveSectionAsync(1, createRequest)); }
public async Task UpdateHiveSection_CreateFiveElement_UpdateOneElement( [Frozen] Mock <IProductStoreHiveContext> contex, HiveSectionService service, IFixture fixture) { var hiveSection = fixture.CreateMany <StoreHiveSection>(5).ToList(); var hive = fixture.CreateMany <StoreHive>(3).ToArray(); contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSection); contex.Setup(x => x.Hives).ReturnsEntitySet(hive); var hiveSectionUpdate = fixture.Create <UpdateHiveSectionRequest>(); await service.UpdateHiveSectionAsync(hiveSection[0].Id, hiveSectionUpdate); var result = await service.GetHiveSectionAsync(hiveSection[0].Id); result.Name.Should().Be(hiveSectionUpdate.Name); }
public async Task UpdateHiveSection_RequestedResourceHasConflictException( [Frozen] Mock <IProductStoreHiveContext> contex, HiveSectionService service, IFixture fixture) { var hiveSection = fixture.CreateMany <StoreHiveSection>(5).ToList(); var hive = fixture.CreateMany <StoreHive>(3).ToArray(); contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSection); contex.Setup(x => x.Hives).ReturnsEntitySet(hive); Func <Task> act = async() => await service.UpdateHiveSectionAsync( hiveSection[0].Id, new UpdateHiveSectionRequest { Code = hiveSection[1].Code, Name = hiveSection[1].Name }); act.Should().Throw <RequestedResourceHasConflictException>(); }
public async Task UpdateHiveSectionAsync_HiveId_UpdateHiveRequest_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { var hiveSectionId = 1; var dbUpdateRequest = fixture.Create <UpdateHiveSectionRequest>(); var dbHiveSections = fixture.CreateMany <StoreHiveSection>(1).ToList(); dbHiveSections[0].Id = hiveSectionId + 1; dbHiveSections[0].Code = $"{dbUpdateRequest.Code}1"; context.Setup(s => s.Sections).ReturnsEntitySet(dbHiveSections); await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.UpdateHiveSectionAsync(hiveSectionId, dbUpdateRequest)); }
public async Task UpdateHiveSectionAsync_UpdateRequestAsParametr_NotExistedHiveId_ThrowException() { var updateReq = new UpdateHiveSectionRequest() { Name = "UpdateName", Code = "TEST2", HiveId = 2 }; var hiveId = 10; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveSectionAsync(hiveId, updateReq)); }
public async Task UpdateHiveSection_TryUpdateHiveSection_UpdatedHiveSectionReturned( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { var existedHiveSection = new StoreHiveSection { Id = 1, Code = "Code" }; var newHiveSection = new UpdateHiveSectionRequest { Code = "newCode" }; context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { existedHiveSection }); var updatedHiveSection = await service.UpdateHiveSectionAsync(existedHiveSection.Id, newHiveSection); Assert.True(updatedHiveSection.Code == newHiveSection.Code); }
public async void UpdateHiveSectionSuccessfull() { 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 HiveSectionService(productContext.Object, userContext.Object); var updateRequest = new UpdateHiveSectionRequest() { Id = 1, Code = "11", Name = "name" }; await service.UpdateHiveSectionAsync(1, updateRequest); }
public async Task UpdateHiveSectionAsync_HiveSectionId_UpdateHiveSectionRequest_Success( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { var hiveId = 1; var dbUpdateRequest = fixture.Create <UpdateHiveSectionRequest>(); var dbHiveSections = fixture.CreateMany <StoreHiveSection>(1).ToList(); dbHiveSections[0].Id = hiveId; dbHiveSections[0].Code = $"{dbUpdateRequest.Code} + 1"; context.Setup(s => s.Sections).ReturnsEntitySet(dbHiveSections); var updateHiveSection = await service.UpdateHiveSectionAsync(hiveId, dbUpdateRequest); Assert.Equal(dbUpdateRequest.Name, updateHiveSection.Name); Assert.Equal(dbUpdateRequest.Code, updateHiveSection.Code); }
public async Task UpdateHiveAsync_PassesHiveIdAndUpdateHiveRequest_ExpectsSuccessfullEqualityAssertion( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, IFixture fixture) { var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList(); var storeHives = fixture.CreateMany <StoreHive>(3).ToList(); contextMock.Setup(x => x.Hives).ReturnsEntitySet(storeHives); contextMock.Setup(x => x.Sections).ReturnsEntitySet(storeHiveSections); var createRequest = new UpdateHiveSectionRequest { Name = "qwerty", Code = "12345", HiveId = storeHives[0].Id }; var expectedHiveSection = await hiveSectionService.UpdateHiveSectionAsync(storeHiveSections[1].Id, createRequest); var actualHiveSection = await hiveSectionService.GetHiveSectionAsync(expectedHiveSection.Id); Assert.Equal(expectedHiveSection.Name, actualHiveSection.Name); Assert.Equal(expectedHiveSection.Code, actualHiveSection.Code); Assert.Equal(expectedHiveSection.HiveId, actualHiveSection.HiveId); }
public async Task UpdateHiveSectionAsync_UpdateRequestAsParametr_ReturnedUpdatedElement() { var updateReq = new UpdateHiveSectionRequest() { Name = "UpdateName", Code = "TEST1", HiveId = 2 }; var hiveSectionId = 1; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); var hiveSection = await service.UpdateHiveSectionAsync(hiveSectionId, updateReq); Assert.Equal(updateReq.Name, hiveSection.Name); Assert.Equal(updateReq.Code, hiveSection.Code); Assert.Equal(updateReq.HiveId, hiveSection.HiveId); }
public async Task UpdateHiveSection_UpdateHiveSectionWithExistedCode_ExceptionThrown( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { var existedHiveSection = new StoreHiveSection { Id = 1, Code = "Code" }; var updatedExistedHiveSection = new StoreHiveSection { Id = 2, Code = "Code1" }; var newHiveSection = new UpdateHiveSectionRequest { Code = "Code" }; context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { existedHiveSection, updatedExistedHiveSection }); await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.UpdateHiveSectionAsync(updatedExistedHiveSection.Id, newHiveSection)); }
public async Task UpdateHiveSection_UpdateWithUnExistedId_ExceptionThrown( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.UpdateHiveSectionAsync(1, new UpdateHiveSectionRequest())); }