public void AddRange_TwoValidHairColors_CountIncreasedByTwo() { Start: var notExistsHairColorCode1 = PreDefinedData.GetNotExistsHairColorCode(); var notExistsHairColorCode2 = PreDefinedData.GetNotExistsHairColorCode(); if (notExistsHairColorCode1 == notExistsHairColorCode2) { goto Start; } var newHairColors = new Collection <ReferenceHairColor> { new ReferenceHairColor { Code = notExistsHairColorCode1, LongName = "" }, new ReferenceHairColor { Code = notExistsHairColorCode2, LongName = "" } }; UnitOfWork.ReferenceHairColors.AddRange(newHairColors); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceHairColors.GetAll(); Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceHairColors.Length + newHairColors.Count)); }
public void AddRange_TwoValidHairColorsDuplicated_ThrowsInvalidOperationException() { var notExistsHairColorCode = PreDefinedData.GetNotExistsHairColorCode(); var newHairColors = new Collection <ReferenceHairColor> { new ReferenceHairColor { Id = int.MaxValue, Code = notExistsHairColorCode, LongName = "" }, new ReferenceHairColor { Id = int.MaxValue, Code = notExistsHairColorCode, LongName = "" } }; Assert.That(() => UnitOfWork.ReferenceHairColors.AddRange(newHairColors), Throws.InvalidOperationException); }
public void Add_ValidHairColorNotExists_FetchNewHairColor() { var notExistsHairColorCode = PreDefinedData.GetNotExistsHairColorCode(); var newReferenceHairColor = new ReferenceHairColor { Code = notExistsHairColorCode, LongName = notExistsHairColorCode }; UnitOfWork.ReferenceHairColors.Add(newReferenceHairColor); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceHairColors.Get(newReferenceHairColor.Id); Assert.That(result, Is.Not.Null); AssertHelper.AreObjectsEqual(newReferenceHairColor, result); }
public async Task Update_InvalidHairColor_HttpNotFound() { // Arrange var notExistsHairColorCode = PreDefinedData.GetNotExistsHairColorCode(); var path = GetRelativePath(nameof(ReferenceHairColorsController), int.MaxValue.ToString()); var apiUpdatingHairColor = new ReferenceHairColorDto { Id = int.MaxValue, Code = notExistsHairColorCode, LongName = "Update" }; // Act var response = await Client.PutAsync(path, new StringContent( JsonConvert.SerializeObject(apiUpdatingHairColor), Encoding.UTF8, JsonMediaType)); // Assert Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }
public async Task Create_ValidPayload_HttpCreatedAndReturnsNewHairColor() { // Arrange var path = GetRelativePath(nameof(ReferenceHairColorsController)); var notExistsHairColorCode = PreDefinedData.GetNotExistsHairColorCode(); var newHairColorDto = new ReferenceHairColorDto { Code = notExistsHairColorCode, LongName = "New", CreatedDate = DateTime.UtcNow, CreatedBy = CreatedModifiedBy, ModifiedDate = DateTime.UtcNow, ModifiedBy = CreatedModifiedBy }; // Act var response = await Client.PostAsync(path, new StringContent( JsonConvert.SerializeObject(newHairColorDto), Encoding.UTF8, JsonMediaType)); var responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.DoesNotThrow( () => response.EnsureSuccessStatusCode(), string.Format(HttpExceptionFormattedMessage, responseString)); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created)); var apiReturnedObject = JsonConvert.DeserializeObject <ReferenceHairColorDto>(responseString); Assert.That(apiReturnedObject.Id, Is.GreaterThan(0)); newHairColorDto.Id = apiReturnedObject.Id; AssertHelper.AreObjectsEqual(apiReturnedObject, newHairColorDto); }