public void AddRange_TwoValidReligions_CountIncreasedByTwo() { Start: var notExistsReligionCode1 = PreDefinedData.GetNotExistsReligionCode(); var notExistsReligionCode2 = PreDefinedData.GetNotExistsReligionCode(); if (notExistsReligionCode1 == notExistsReligionCode2) { goto Start; } var newReligions = new Collection <ReferenceReligion> { new ReferenceReligion { Code = notExistsReligionCode1, LongName = "" }, new ReferenceReligion { Code = notExistsReligionCode2, LongName = "" } }; UnitOfWork.ReferenceReligions.AddRange(newReligions); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceReligions.GetAll(); Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceReligions.Length + newReligions.Count)); }
public void AddRange_TwoValidReligionsDuplicated_ThrowsInvalidOperationException() { var notExistsReligionCode = PreDefinedData.GetNotExistsReligionCode(); var newReligions = new Collection <ReferenceReligion> { new ReferenceReligion { Id = int.MaxValue, Code = notExistsReligionCode, LongName = "" }, new ReferenceReligion { Id = int.MaxValue, Code = notExistsReligionCode, LongName = "" } }; Assert.That(() => UnitOfWork.ReferenceReligions.AddRange(newReligions), Throws.InvalidOperationException); }
public void Add_ValidReligionNotExists_FetchNewReligion() { var notExistsReligionCode = PreDefinedData.GetNotExistsReligionCode(); var newReferenceReligion = new ReferenceReligion { Code = notExistsReligionCode, LongName = notExistsReligionCode }; UnitOfWork.ReferenceReligions.Add(newReferenceReligion); UnitOfWork.Complete(); var result = UnitOfWork.ReferenceReligions.Get(newReferenceReligion.Id); Assert.That(result, Is.Not.Null); AssertHelper.AreObjectsEqual(newReferenceReligion, result); }
public async Task Update_InvalidReligion_HttpNotFound() { // Arrange var notExistsReligionCode = PreDefinedData.GetNotExistsReligionCode(); var path = GetRelativePath(nameof(ReferenceReligionsController), int.MaxValue.ToString()); var apiUpdatingReligion = new ReferenceReligionDto { Id = int.MaxValue, Code = notExistsReligionCode, LongName = "Update Test" }; // Act var response = await Client.PutAsync(path, new StringContent( JsonConvert.SerializeObject(apiUpdatingReligion), Encoding.UTF8, JsonMediaType)); // Assert Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }
public async Task Create_ValidPayload_HttpCreatedAndReturnsNewReligion() { // Arrange var path = GetRelativePath(nameof(ReferenceReligionsController)); var notExistsReligionCode = PreDefinedData.GetNotExistsReligionCode(); var newReligionDto = new ReferenceReligionDto { Code = notExistsReligionCode, LongName = "New Religion", CreatedDate = DateTime.UtcNow, CreatedBy = CreatedModifiedBy, ModifiedDate = DateTime.UtcNow, ModifiedBy = CreatedModifiedBy }; // Act var response = await Client.PostAsync(path, new StringContent( JsonConvert.SerializeObject(newReligionDto), 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 <ReferenceReligionDto>(responseString); Assert.That(apiReturnedObject.Id, Is.GreaterThan(0)); newReligionDto.Id = apiReturnedObject.Id; AssertHelper.AreObjectsEqual(apiReturnedObject, newReligionDto); }