public async Task UpdateDroid_WithValidNameAndNickname_DroidUpdatedSuccessfully() { // Arrange var droidDto = new DroidDto { DroidId = _existingDroidId, CreationDate = DateTimeOffset.Now, Name = "Didi", Nickname = "Di", }; var armDtoList = new List <IArmDto> { new ArmDto { DroidId = _existingDroidId, ArmId = Guid.NewGuid() } }; var droid = Droid.FromDto(droidDto).WithArms(armDtoList); // Act await _repo.UpdateAsync(droid); var droidSelected = await _repo.GetBySerialNumberAsync(_existingDroidId, Droid.AssertExists); // Assert droidSelected.Name.Should().Be("Didi"); droidSelected.Nickname.Should().Be("Di"); }
public async Task CreateDroid_WithDroidSet_DroidCreatedSuccessfully() { // Arrange var newDroidId = new Guid("c29a188b-a562-47b4-a74c-9e82702e0986"); var droidDto = new DroidDto { DroidId = newDroidId, CreationDate = DateTimeOffset.Now, Name = "Dada", Nickname = "Da", Quote = "Votre manque de foi me consterne. - Dark Vador" }; var armDtoList = new List <IArmDto> { new ArmDto { DroidId = newDroidId, ArmId = Guid.NewGuid() } }; var droid = Droid.FromDto(droidDto).WithArms(armDtoList); // Act await _repo.InsertAsync(droid); var droidSelected = await _repo.GetBySerialNumberAsync(newDroidId, Droid.AssertExists); // Assert droidSelected.DroidId.Should().Be(Guid.Parse("c29a188b-a562-47b4-a74c-9e82702e0986")); droidSelected.Name.Should().Be("Dada"); droidSelected.Nickname.Should().Be("Da"); droidSelected.Quote.Should().Be("Votre manque de foi me consterne. - Dark Vador"); }
public async Task GetDroid_WithValidSerialNumber_ReturnsDroidAsync() { // Arrange IDroidDto droid = new DroidDto { DroidId = Guid.Parse("341d9e5b-ae06-4c06-ba4f-7256317792cd"), CreationDate = new DateTime(2019, 02, 06), Name = "Toto", Nickname = "To" }; _repo .Setup(x => x.GetBySerialNumberAsync(droid.DroidId, Droid.AssertExists)) .Returns(Task.FromResult(droid)); // Act var httpResponse = await _controller.GetAsync(droid.DroidId); var result = (ObjectResult)httpResponse.Result; var element = (DroidViewModel)result.Value; // Assert result.StatusCode.Should().Be((int)HttpStatusCode.OK); element.SerialNumber.Should().Be(droid.DroidId); element.Name.Should().Be(droid.Name); element.Nickname.Should().Be(droid.Nickname); }
public async Task GetArmForDroid_WithValidDroidId_ReturnsDroidArmListAsync() { // Arrange var serialNumber = Guid.Parse("7e202cf3-d50f-4d70-bab9-c0f3a35c5bb2"); IReadOnlyCollection <IArmDto> arms = new List <IArmDto> { new ArmDto { DroidId = serialNumber, ArmId = Guid.Parse("e863e570-4516-4966-8920-93cd5c9a6e3e") }, new ArmDto { DroidId = serialNumber, ArmId = Guid.Parse("cffc1357-6b1b-49b0-8020-c59d22de9162") } }; IDroidDto droidDto = new DroidDto { DroidId = Guid.Parse("7e202cf3-d50f-4d70-bab9-c0f3a35c5bb2"), CreationDate = DateTimeOffset.Now, Name = "test", Nickname = "test", Quote = "quote" }; _repo .Setup(x => x.GetDroidArmsAsync(serialNumber)) .Returns(Task.FromResult(arms)); _repoDroid .Setup(r => r.GetBySerialNumberAsync(serialNumber, It.IsAny <Action <IDroidUnicityValidationInfo> >())) .Returns(Task.FromResult(droidDto)); // Act var httpResponse = await _controller.GetAsync(serialNumber); var result = (ObjectResult)httpResponse.Result; var armsResult = (ICollection <ArmViewModel>)result.Value; // Assert result.StatusCode.Should().Be((int)HttpStatusCode.OK); armsResult.Should().HaveCount(arms.Count); var armIds = arms.Select(a => a.ArmId); var armIdsResult = armsResult.Select(a => a.SerialNumber); var allSame = armIds.All(armId => armIdsResult.Contains(armId)); allSame.Should().BeTrue(); }
public async Task InsertDroid_WithValidDroid_ReturnsEqualDroidAsync() { // Arrange var createDroid = new CreateDroid("Toto", "To"); var droidDto = new DroidDto { DroidId = Guid.Parse("341d9e5b-ae06-4c06-ba4f-7256317792cd"), CreationDate = new DateTime(2019, 02, 06), Name = "Toto", Nickname = "To" }; var armDtoList = new List <IArmDto> { new ArmDto { DroidId = droidDto.DroidId, ArmId = Guid.NewGuid() } }; var droid = Droid.FromDto(droidDto).WithArms(armDtoList); _handler .Setup(x => x.HandleAsync(createDroid)) .Returns(Task.FromResult(droid)); // Act var httpResponse = await _controller.PostAsync(createDroid); var result = (ObjectResult)httpResponse; var element = (DroidViewModel)result.Value; // Assert result.StatusCode.Should().Be((int)HttpStatusCode.Created); element.SerialNumber.Should().Be(droidDto.DroidId); element.Name.Should().Be(droidDto.Name); element.Nickname.Should().Be(droidDto.Nickname); }
public Droid(DroidDto dto, StarWarsData data) { _dto = dto ?? throw new ArgumentNullException(nameof(dto)); _data = data ?? throw new ArgumentNullException(nameof(data)); }