public void AddRange_TwoValidEyeColors_CountIncreasedByTwo() { Start: var notExistsEyeColorCode1 = PreDefinedData.GetNotExistsEyeColorCode(); var notExistsEyeColorCode2 = PreDefinedData.GetNotExistsEyeColorCode(); if (notExistsEyeColorCode1 == notExistsEyeColorCode2) { goto Start; } var newEyeColors = new Collection <ReferenceEyeColor> { new ReferenceEyeColor { Code = notExistsEyeColorCode1, LongName = "" }, new ReferenceEyeColor { Code = notExistsEyeColorCode2, LongName = "" } }; UnitOfWork.ReferenceEyeColors.AddRange(newEyeColors); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceEyeColors.GetAll(); Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceEyeColors.Length + newEyeColors.Count)); }
public void AddRange_TwoValidEyeColorsDuplicated_ThrowsInvalidOperationException() { var notExistsEyeColorCode = PreDefinedData.GetNotExistsEyeColorCode(); var newEyeColors = new Collection <ReferenceEyeColor> { new ReferenceEyeColor { Id = int.MaxValue, Code = notExistsEyeColorCode, LongName = "" }, new ReferenceEyeColor { Id = int.MaxValue, Code = notExistsEyeColorCode, LongName = "" } }; Assert.That(() => UnitOfWork.ReferenceEyeColors.AddRange(newEyeColors), Throws.InvalidOperationException); }
public void Add_ValidEyeColorNotExists_FetchNewEyeColor() { var notExistsEyeColorCode = PreDefinedData.GetNotExistsEyeColorCode(); var newReferenceEyeColor = new ReferenceEyeColor { Code = notExistsEyeColorCode, LongName = notExistsEyeColorCode }; UnitOfWork.ReferenceEyeColors.Add(newReferenceEyeColor); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceEyeColors.Get(newReferenceEyeColor.Id); Assert.That(result, Is.Not.Null); AssertHelper.AreObjectsEqual(newReferenceEyeColor, result); }
public async Task Update_InvalidEyeColor_HttpNotFound() { // Arrange var notExistsEyeColorCode = PreDefinedData.GetNotExistsEyeColorCode(); var path = GetRelativePath(nameof(ReferenceEyeColorsController), int.MaxValue.ToString()); var apiUpdatingEyeColor = new ReferenceEyeColorDto { Id = int.MaxValue, Code = notExistsEyeColorCode, LongName = "Update Test" }; // Act var response = await Client.PutAsync(path, new StringContent( JsonConvert.SerializeObject(apiUpdatingEyeColor), Encoding.UTF8, JsonMediaType)); // Assert Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }
public async Task Create_ValidPayload_HttpCreatedAndReturnsNewEyeColor() { // Arrange var path = GetRelativePath(nameof(ReferenceEyeColorsController)); var notExistsEyeColorCode = PreDefinedData.GetNotExistsEyeColorCode(); var newEyeColorDto = new ReferenceEyeColorDto { Code = notExistsEyeColorCode, LongName = "New EyeColor", CreatedDate = DateTime.UtcNow, CreatedBy = CreatedModifiedBy, ModifiedDate = DateTime.UtcNow, ModifiedBy = CreatedModifiedBy }; // Act var response = await Client.PostAsync(path, new StringContent( JsonConvert.SerializeObject(newEyeColorDto), 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 <ReferenceEyeColorDto>(responseString); Assert.That(apiReturnedObject.Id, Is.GreaterThan(0)); newEyeColorDto.Id = apiReturnedObject.Id; AssertHelper.AreObjectsEqual(apiReturnedObject, newEyeColorDto); }