public async Task PrimaryObjectService_DeleteAsync_Valid() { // This test verifies that DeleteAsync works with valid inputs var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description", Name = "Name", SecondaryObjects = new List <DomainModels.SecondaryObject>() { new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", }, new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 2", Name = "Name 2", }, }, }; foreach (var sourceSecondaryObject in source.SecondaryObjects) { sourceSecondaryObject.PrimaryObject = source; sourceSecondaryObject.PrimaryObject_Id = source.Id; } _primaryObjectRepository.Setup(_ => _.GetByIdAsync(source.Id)).ReturnsAsync(source); await primaryObjectService.DeleteAsync(source.Id); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task PrimaryObjectService_UpdateAsync_InputModel_Name_WhiteSpace() { // This test verifies that the UpdateAsync will not accept invalid inputs var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = "New Description", Name = " ", }; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => new DomainModels.PrimaryObject(id) { Description = "Description", Name = "Name", SecondaryObjects = new List <DomainModels.SecondaryObject>() { new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", }, new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 2", Name = "Name 2", }, }, }); await primaryObjectService.UpdateAsync(Guid.NewGuid(), source); }
public async Task PrimaryObjectService_GetAsync_Id_Empty() { // This test verifies that the GetAsync will not accept null dependencies var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var destination = await primaryObjectService.GetAsync(Guid.Empty); }
public async Task PrimaryObjectService_CreateAsync_InputModel_Null() { // This test verifies that the CreateAsync will not accept null dependencies var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); ApiModels.PrimaryObject source = null; var destination = await primaryObjectService.CreateAsync(source); }
public async Task PrimaryObjectService_DeleteAsync_NotFound() { // This test verifies that DeleteAsync throws an error when the object is not found var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = Guid.NewGuid(); _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(null as DomainModels.PrimaryObject); await primaryObjectService.DeleteAsync(source); }
public async Task PrimaryObjectService_UpdateAsync_InputModel_Null() { // This test verifies that the UpdateAsync will not accept null dependencies var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); ApiModels.PrimaryObject source = null; await primaryObjectService.UpdateAsync(Guid.NewGuid(), source); }
public async Task PrimaryObjectService_GetAllAsync_Valid() { // This test verifies that GetAllAsync works var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); _primaryObjectRepository.Setup(_ => _.GetAllAsync()).ReturnsAsync(new List <DomainModels.PrimaryObject>()); var destination = await primaryObjectService.GetAllAsync(); Assert.IsNotNull(destination); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Never); }
public async Task PrimaryObjectService_UpdateAsync() { // This test verifies that UpdateAsync works with valid inputs var service = new PrimaryObjectService(_apiClient.Object); _apiClient.Setup(_ => _.UpdateAsync(It.IsAny <string>(), It.IsAny <Mvc.Contracts.Models.PrimaryObject>())) .ReturnsAsync(new Mvc.Contracts.Models.PrimaryObject()); var result = await service.UpdateAsync(Guid.NewGuid(), new Mvc.Models.PrimaryObject()); Assert.IsNotNull(result); }
public async Task PrimaryObjectService_GetAllAsync() { // This test verifies that GetAllAsync works with valid inputs var service = new PrimaryObjectService(_apiClient.Object); _apiClient.Setup(_ => _.GetAsync <IEnumerable <Mvc.Contracts.Models.PrimaryObject> >(It.IsAny <string>())) .ReturnsAsync(new Mvc.Contracts.Models.PrimaryObject[0]); var result = await service.GetAllAsync(); Assert.IsNotNull(result); }
public async Task PrimaryObjectService_CreateAsync_InputModel_Description_Null() { // This test verifies that the CreateAsync will not accept invalid inputs var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = null, Name = "New Name", }; var destination = await primaryObjectService.CreateAsync(source); }
public async Task PrimaryObjectService_UpdateAsync_Id_Empty() { // This test verifies that the UpdateAsync will not accept null dependencies var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = "New Description", Name = "New Name", }; await primaryObjectService.UpdateAsync(Guid.Empty, source); }
public async Task PrimaryObjectService_UpdateAsync_NotFound() { // This test verifies that UpdateAsync throws an error when the object is not found var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = "New Description", Name = "New Name", }; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(null as DomainModels.PrimaryObject); await primaryObjectService.UpdateAsync(Guid.NewGuid(), source); }
public async Task PrimaryObjectService_CreateAsync_Valid() { // This test verifies that CreateAsync works with valid inputs var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = "New Description", Name = "New Name", }; var destination = await primaryObjectService.CreateAsync(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.SecondaryObjects); Assert.AreEqual(0, destination.SecondaryObjects.Count); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task PrimaryObjectService_UpdateAsync_Valid() { // This test verifies that UpdateAsync works with valid inputs var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); var source = new ApiModels.PrimaryObject() { Description = "New Description", Name = "New Name", }; _primaryObjectRepository.Setup(_ => _.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync((Guid id) => new DomainModels.PrimaryObject(id) { Description = "Description", Name = "Name", SecondaryObjects = new List <DomainModels.SecondaryObject>() { new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", }, new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 2", Name = "Name 2", }, }, }); var destination = await primaryObjectService.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.SecondaryObjects); _unitOfWork.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public async Task PrimaryObjectService_DeleteAsync() { // This test verifies that DeleteAsync works with valid inputs var service = new PrimaryObjectService(_apiClient.Object); await service.DeleteAsync(Guid.NewGuid()); }
public void PrimaryObjectService_Constructor_UnitOfWork_Null() { // This test verifies that the service will not accept null dependencies var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, null); }
public void PrimaryObjectService_Constructor_Valid() { // This test verifies that the service can be constructed successfully var service = new PrimaryObjectService(_apiClient.Object); }
public void PrimaryObjectService_Constructor_Valid() { // This test verifies that the service can be constructed successfully var primaryObjectService = new PrimaryObjectService(_primaryObjectRepository.Object, _secondaryObjectRepository.Object, _unitOfWork.Object); }
public void PrimaryObjectService_Constructor_ApiClient_Null() { // This test verifies that the service will not accept null dependencies var service = new PrimaryObjectService(null); }