コード例 #1
0
        public async Task <ActionResult> PutAsync([FromRoute] Guid serialNumber, [FromBody] UpdateDroid updateDroid)
        {
            try
            {
                updateDroid.WithSerialNumber(serialNumber);
                await _droidHandler.HandleAsync(updateDroid);

                return(NoContent());
            }
            catch (BusinessException ex) { return(ex.GetStatusCode()); }
        }
コード例 #2
0
        public async Task UpdateDroid_WithInvalidDroidName_ReturnsConflictStatusCodeAsync()
        {
            // Arrange
            var serialNumber = Guid.Parse("341d9e5b-ae06-4c06-ba4f-7256317792cd");
            var updateDroid  = new UpdateDroid("Toto", "To", serialNumber);

            _handler
            .Setup(x => x.HandleAsync(updateDroid))
            .Throws <DroidConflictNameException>();

            // Act
            var httpResponse = await _controller.PutAsync(serialNumber, updateDroid);

            var httpCode = ((StatusCodeResult)httpResponse).StatusCode;

            // Assert
            httpCode.Should().Be((int)HttpStatusCode.Conflict);
        }
コード例 #3
0
        public async Task UpdateDroid_WithValidDroid_ReturnsNoContentStatusCodeAsync()
        {
            // Arrange
            var serialNumber = Guid.Parse("341d9e5b-ae06-4c06-ba4f-7256317792cd");
            var updateDroid  = new UpdateDroid("Toto", "To", serialNumber);

            _handler
            .Setup(x => x.HandleAsync(updateDroid))
            .Returns(Task.CompletedTask);

            // Act
            var httpResponse = await _controller.PutAsync(serialNumber, updateDroid);

            var httpCode = ((StatusCodeResult)httpResponse).StatusCode;

            // Assert
            httpCode.Should().Be((int)HttpStatusCode.NoContent);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Droid.cs プロジェクト: Cdiscount/dotnet-challenge
 internal Task <Droid> UpdateAsync(Func <DroidName, Task <bool> > nameAlreadyExistsAsync, UpdateDroid updateDroid)
 => SetNickname(updateDroid.Nickname).SetNameAsync(nameAlreadyExistsAsync, updateDroid.Name);