public async Task SecondaryObjectService_GetAsync_Valid() { // This test verifies that GetAsync works with valid inputs var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", PrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description", Name = "Name", }, }; source.PrimaryObject_Id = source.PrimaryObject.Id; source.PrimaryObject.SecondaryObjects = new List <DomainModels.SecondaryObject>() { source }; _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(source.Id)).ReturnsAsync(source); var destination = await secondaryObjectService.GetAsync(source.Id); Assert.AreEqual(source, destination); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Never); }
public async Task SecondaryObjectService_UpdateAsync_Valid() { // This test verifies that UpdateAsync works with valid inputs var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = "New Description", Name = "New Name", }; _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => new DomainModels.SecondaryObject(id) { Description = "Description 1", Name = "Name 1", PrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description", Name = "Name", }, }); var destination = await secondaryObjectService.UpdateAsync(Guid.NewGuid(), source); Assert.IsNotNull(destination); Assert.AreEqual(source.Description, destination.Description); Assert.AreNotEqual(Guid.Empty, destination.Id); Assert.AreEqual(source.Name, destination.Name); Assert.IsNotNull(destination.PrimaryObject); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task SecondaryObjectService_UpdateAsync_InputModel_Null() { // This test verifies that the UpdateAsync will not accept null dependencies var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); ApiModels.SecondaryObject source = null; await secondaryObjectService.UpdateAsync(Guid.NewGuid(), source); }
public async Task SecondaryObjectService_DeleteAsync_NotFound() { // This test verifies that DeleteAsync throws an error when the object is not found var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = Guid.NewGuid(); _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(null as DomainModels.SecondaryObject); await secondaryObjectService.DeleteAsync(source); }
public async Task SecondaryObjectService_CreateAsync_InputModel_Null() { // This test verifies that the CreateAsync will not accept null dependencies var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); ApiModels.SecondaryObject source = null; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync((Guid id) => new DomainModels.PrimaryObject(id)); var destination = await secondaryObjectService.CreateAsync(Guid.NewGuid(), source); }
public async Task SecondaryObjectService_CreateAsync_PrimaryObjectId_Empty() { // This test verifies that the CreateAsync will not accept null dependencies var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = "New Description", Name = "New Name", }; var destination = await secondaryObjectService.CreateAsync(Guid.Empty, source); }
public async Task SecondaryObjectService_GetAllAsync() { // This test verifies that GetAllAsync works with valid inputs var service = new SecondaryObjectService(_apiClient.Object); _apiClient.Setup(_ => _.GetAsync <IEnumerable <Mvc.Contracts.Models.SecondaryObject> >(It.IsAny <string>())) .ReturnsAsync(new Mvc.Contracts.Models.SecondaryObject[0]); var result = await service.GetAllAsync(); Assert.IsNotNull(result); }
public async Task SecondaryObjectService_GetAllAsync_Valid() { // This test verifies that GetAllAsync works var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); _secondaryObjectRepository.Setup(_ => _.GetAllAsync()).ReturnsAsync(new List <DomainModels.SecondaryObject>()); var destination = await secondaryObjectService.GetAllAsync(); Assert.IsNotNull(destination); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Never); }
public async Task SecondaryObjectService_DeleteAsync_Valid() { // This test verifies that DeleteAsync works with valid inputs var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = Guid.NewGuid(); _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync((Guid id) => new DomainModels.SecondaryObject(id)); await secondaryObjectService.DeleteAsync(source); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task SecondaryObjectService_UpdateAsync() { // This test verifies that UpdateAsync works with valid inputs var service = new SecondaryObjectService(_apiClient.Object); _apiClient.Setup(_ => _.UpdateAsync(It.IsAny <string>(), It.IsAny <Mvc.Contracts.Models.SecondaryObject>())) .ReturnsAsync(new Mvc.Contracts.Models.SecondaryObject()); var result = await service.UpdateAsync(Guid.NewGuid(), new Mvc.Models.SecondaryObject()); Assert.IsNotNull(result); }
public async Task SecondaryObjectService_CreateAsync_PrimaryObject_NotFound() { // This test verifies that CreateAsync throws an error when the primary object is not found var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = "New Description", Name = "New Name", }; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(null as DomainModels.PrimaryObject); var destination = await secondaryObjectService.CreateAsync(Guid.NewGuid(), source); }
public async Task SecondaryObjectService_CreateAsync_InputModel_Name_WhiteSpace() { // This test verifies that the CreateAsync will not accept invalid inputs var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = "New Description", Name = " ", }; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync((Guid id) => new DomainModels.PrimaryObject(id)); var destination = await secondaryObjectService.CreateAsync(Guid.NewGuid(), source); }
public async Task SecondaryObjectService_UpdateAsync_NotFound() { // This test verifies that UpdateAsync throws an error when the object is not found var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = "New Description", Name = "New Name", }; _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(null as DomainModels.SecondaryObject); await secondaryObjectService.UpdateAsync(Guid.NewGuid(), source); Assert.Fail("Expected exception was not thrown"); }
public async Task SecondaryObjectService_UpdateAsync_InputModel_Description_Empty() { // This test verifies that the UpdateAsync will not accept invalid inputs var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.SecondaryObject() { Description = string.Empty, Name = "New Name", }; _secondaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => new DomainModels.SecondaryObject(id) { Description = "Description 1", Name = "Name 1", PrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description", Name = "Name", }, }); var destination = await secondaryObjectService.UpdateAsync(Guid.NewGuid(), source); }
public async Task SecondaryObjectService_GetAsync_Id_Empty() { // This test verifies that the GetAsync will not accept null dependencies var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var destination = await secondaryObjectService.GetAsync(Guid.Empty); }
public async Task SecondaryObjectService_DeleteAsync() { // This test verifies that DeleteAsync works with valid inputs var service = new SecondaryObjectService(_apiClient.Object); await service.DeleteAsync(Guid.NewGuid()); }
public void SecondaryObjectService_Constructor_Valid() { // This test verifies that the service can be constructed successfully var service = new SecondaryObjectService(_apiClient.Object); }
public void SecondaryObjectService_Constructor_ApiClient_Null() { // This test verifies that the service will not accept null dependencies var service = new SecondaryObjectService(null); }
public void SecondaryObjectService_Constructor_Valid() { // This test verifies that the service can be constructed successfully var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); }
public void SecondaryObjectService_Constructor_UnitOfWork_Null() { // This test verifies that the service will not accept null dependencies var secondaryObjectService = new SecondaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, null); }