public async Task Get_ValidBloodTypeCode_HttpOkAndReturnsSingleBloodType()
        {
            // Arrange
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), randomBloodTypeId.ToString());

            // Act
            var response = await Client.GetAsync(path);

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.DoesNotThrow(
                () => response.EnsureSuccessStatusCode(),
                string.Format(HttpExceptionFormattedMessage, responseString));
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

            var apiReturnedObject =
                JsonConvert.DeserializeObject <ReferenceBloodTypeDto>(responseString);

            var preDefinedObject =
                PreDefinedData.ReferenceBloodTypes
                .SingleOrDefault(c => c.Id == randomBloodTypeId);

            AssertHelper.AreObjectsEqual(apiReturnedObject,
                                         Mapper.Map <ReferenceBloodType, ReferenceBloodTypeDto>(preDefinedObject));
        }
        public async Task Update_ValidBloodType_HttpNoContent()
        {
            // Arrange
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();

            var apiUpdatingBloodType = UnitOfWork.ReferenceBloodTypes.Get(randomBloodTypeId);

            apiUpdatingBloodType.LongName = "Update Test";
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), randomBloodTypeId.ToString());

            // Act
            var response = await Client.PutAsync(path, new StringContent(
                                                     JsonConvert.SerializeObject(Mapper.Map <ReferenceBloodType, ReferenceBloodTypeDto>(apiUpdatingBloodType)),
                                                     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.NoContent));

            var dbUpdatedBloodType = UnitOfWork.ReferenceBloodTypes.Get(apiUpdatingBloodType.Id);

            AssertHelper.AreObjectsEqual(apiUpdatingBloodType, dbUpdatedBloodType);
        }
示例#3
0
        public void SingleOrDefault_PredicateUsedToFindMoreOneBloodType_ThrowsInvalidOperationException()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();

            Assert.That(() =>
                        UnitOfWork.ReferenceBloodTypes.SingleOrDefault(p => p.Id != randomBloodTypeId),
                        Throws.InvalidOperationException);
        }
示例#4
0
        public void SingleOrDefault_PredicateUsedToFindOneBloodType_ReturnsOneBloodType()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();

            var result = UnitOfWork.ReferenceBloodTypes.SingleOrDefault(p => p.Id == randomBloodTypeId);

            Assert.That(result, Is.Not.Null);
        }
示例#5
0
        public void Find_PredicateUsedToFindOneBloodType_ReturnsCollection()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();

            var result = UnitOfWork.ReferenceBloodTypes.Find(p => p.Id == randomBloodTypeId);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result.First().Id == randomBloodTypeId);
        }
示例#6
0
        public void Get_ValidBloodTypeCode_ReturnsSingleBloodType()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();

            var result = UnitOfWork.ReferenceBloodTypes.Get(randomBloodTypeId);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Id, Is.EqualTo(randomBloodTypeId));
        }
示例#7
0
        public void Remove_ValidBloodTypeExists_BloodTypeCannotBeFetched()
        {
            var randomBloodTypeId        = PreDefinedData.GetRandomBloodTypeId();
            var removeReferenceBloodType = UnitOfWork.ReferenceBloodTypes.Get(randomBloodTypeId);

            UnitOfWork.ReferenceBloodTypes.Remove(removeReferenceBloodType);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceBloodTypes.Get(removeReferenceBloodType.Id);

            Assert.That(result, Is.Null);
        }
示例#8
0
        public void Add_ValidBloodTypeExists_ThrowsInvalidOperationException()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var randomBloodType   = UnitOfWork.ReferenceBloodTypes.Get(randomBloodTypeId);

            Assert.That(() => UnitOfWork.ReferenceBloodTypes.Add(
                            new ReferenceBloodType
            {
                Id   = randomBloodType.Id,
                Code = randomBloodType.Code
            }),
                        Throws.InvalidOperationException);
        }
        public async Task Update_EmptyPayload_HttpBadRequest()
        {
            // Arrange
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), randomBloodTypeId.ToString());

            // Act
            var response = await Client.PutAsync(path,
                                                 new StringContent(string.Empty, Encoding.UTF8));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
        public async Task Delete_ValidBloodType_HttpNoContent()
        {
            // Arrange
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), randomBloodTypeId.ToString());

            // Act
            var response = await Client.DeleteAsync(path);

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.DoesNotThrow(
                () => response.EnsureSuccessStatusCode(),
                string.Format(HttpExceptionFormattedMessage, responseString));
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
        }
示例#11
0
        public void RemoveRange_TwoValidBloodTypesDuplicated_ThrowsInvalidOperationException()
        {
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var randomBloodType   = UnitOfWork.ReferenceBloodTypes.Get(randomBloodTypeId);

            var existingBloodTypes = new Collection <ReferenceBloodType>
            {
                new ReferenceBloodType {
                    Id = randomBloodType.Id, Code = randomBloodType.Code
                },
                new ReferenceBloodType {
                    Id = randomBloodType.Id, Code = randomBloodType.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceBloodTypes.RemoveRange(existingBloodTypes),
                        Throws.InvalidOperationException);
        }
        public async Task Update_MalformedPayload_HttpBadRequest()
        {
            // Arrange
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), randomBloodTypeId.ToString());
            var apiUpdatingBloodType = new ReferenceBloodTypeDto
            {
                Id = randomBloodTypeId
                     // Code is required, keep it missing
            };

            // Act
            var response = await Client.PutAsync(path, new StringContent(
                                                     JsonConvert.SerializeObject(apiUpdatingBloodType),
                                                     Encoding.UTF8,
                                                     JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
        public async Task Create_ExistingBloodType_HttpConflict()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceBloodTypesController));
            var randomBloodTypeId = PreDefinedData.GetRandomBloodTypeId();
            var randomBloodType   = PreDefinedData.ReferenceBloodTypes[randomBloodTypeId - 1];

            var newBloodTypeDto = new ReferenceBloodTypeDto
            {
                Code        = randomBloodType.Code,
                LongName    = "Create Test",
                CreatedDate = DateTime.UtcNow
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newBloodTypeDto),
                                                      Encoding.UTF8,
                                                      JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict));
        }