public async Task HandleDeleteDroid_WithNonExistantSerialNumber_ThrowsDroidNotFoundException() { // Arrange var droidHandler = new DroidHandler(_repoMock.Object, _repoArmMock.Object, _quoteMock.Object, _encryptionMock.Object); var deleteDroid = new DeleteDroid(_serialNumber); var armIdList = new List <ArmId> { Guid.NewGuid() }; _repoArmMock .Setup(repo => repo.DeleteAsync(armIdList, It.IsAny <object>())) .Returns(Task.FromResult(true)); var actions = DeleteArmListAction.CreateNew(armIdList, _repoArmMock.Object.DeleteAsync); _repoMock .Setup(repo => repo.DeleteAsync(_serialNumber, actions)) .Returns(Task.FromResult(false)); // Act var exception = await Record.ExceptionAsync( () => droidHandler.HandleAsync(deleteDroid)); // Assert exception.Should().BeOfType <DroidNotFoundException>(); }
public async Task HandleCreateArm_WithValidDroidId_ArmCreatedSuccessfully() { // Arrange var droidHandler = new DroidHandler(_repoMock.Object, _repoArmMock.Object, _quoteMock.Object, _encryptionMock.Object); var createArm = new CreateArm(_serialNumber); var getDroidResult = Task.FromResult(_droidDto); _repoMock .Setup(repo => repo.GetBySerialNumberAsync(_serialNumber, Droid.AssertExists)) .Returns(getDroidResult); var getArmResult = Task.FromResult(_armDtoList); _repoArmMock .Setup(repo => repo.GetDroidArmsAsync(_serialNumber)) .Returns(getArmResult); _repoArmMock .Setup(repo => repo.InsertDroidArmAsync(_serialNumber, It.IsAny <Arm>(), It.IsAny <Action <IDroidValidationInfo> >())) .Returns(Task.CompletedTask); // Act await droidHandler.HandleAsync(createArm).ConfigureAwait(false); // Assert _repoArmMock.Verify((r) => r.InsertDroidArmAsync(_serialNumber, It.IsAny <Arm>(), It.IsAny <Action <IDroidValidationInfo> >()), Times.Once); }
public async Task HandleDeleteDroid_WithValidSerialNumber_DeletedCallsSuccessfully() { // Arrange var droidHandler = new DroidHandler(_repoMock.Object, _repoArmMock.Object, _quoteMock.Object, _encryptionMock.Object); var deleteDroid = new DeleteDroid(_serialNumber); var getDroidResult = Task.FromResult(_droidDto); _repoMock .Setup(repo => repo.GetBySerialNumberAsync(_serialNumber, Droid.AssertExists)) .Returns(getDroidResult); IReadOnlyCollection <IArmDto> arms = new List <ArmDto>(); _repoArmMock .Setup(repo => repo.GetDroidArmsAsync(_serialNumber)) .Returns(Task.FromResult(arms)); _repoArmMock .Setup(repo => repo.DeleteAsync(It.IsAny <List <ArmId> >(), It.IsAny <object>())) .Returns(Task.FromResult(true)); _repoMock .Setup(repo => repo.DeleteAsync(_serialNumber, It.IsAny <DeleteArmListAction>())) .Returns(Task.FromResult(true)); // Act await droidHandler.HandleAsync(deleteDroid); // Assert _repoMock.Verify((r) => r.DeleteAsync(_serialNumber, It.IsAny <DeleteArmListAction>()), Times.Once); }
public async Task HandleCreateDroid_WithValidDroid_DroidCreatedSuccessfully() { // Arrange var droidHandler = new DroidHandler(_repoMock.Object, _repoArmMock.Object, _quoteMock.Object, _encryptionMock.Object); var createDroid = new CreateDroid("Toto", "To"); // Act var droidCreated = await droidHandler.HandleAsync(createDroid).ConfigureAwait(false); // Assert _repoMock.Verify((r) => r.DoesNameAlreadyExistsAsync(createDroid.Name), Times.Once); _repoMock.Verify((r) => r.InsertAsync(droidCreated), Times.Once); (droidCreated.Name).Should().Be(createDroid.Name); (droidCreated.Nickname).Should().Be(createDroid.Nickname); }
public async Task HandleUpdateDroid_WithValidName_DroidUpdatedSuccessfully() { // Arrange var droidHandler = new DroidHandler(_repoMock.Object, _repoArmMock.Object, _quoteMock.Object, _encryptionMock.Object); var updateDroid = new UpdateDroid("Toto", "To", _serialNumber); IReadOnlyCollection <IArmDto> armDtoList = new List <ArmDto> { new ArmDto { DroidId = _serialNumber, ArmId = Guid.NewGuid() }, new ArmDto { DroidId = _serialNumber, ArmId = Guid.NewGuid() } }; var getDroidResult = Task.FromResult(_droidDto); _repoMock .Setup(repo => repo.GetBySerialNumberAsync(_serialNumber, Droid.AssertExists)) .Returns(getDroidResult); var getArmResult = Task.FromResult(armDtoList); _repoArmMock .Setup(repo => repo.GetDroidArmsAsync(_serialNumber)) .Returns(getArmResult); // Act await droidHandler.HandleAsync(updateDroid).ConfigureAwait(false); // Assert _repoMock.Verify((r) => r.DoesNameAlreadyExistsAsync(updateDroid.Name), Times.Once); _repoMock.Verify((r) => r.UpdateAsync( It.Is <Droid>( droid => droid.Name == updateDroid.Name && droid.Nickname == updateDroid.Nickname)), Times.Once); }