Пример #1
0
        public void AddRange_TwoValidBloodTypes_CountIncreasedByTwo()
        {
Start:
            var notExistsBloodTypeCode1 = PreDefinedData.GetNotExistsBloodTypeCode();
            var notExistsBloodTypeCode2 = PreDefinedData.GetNotExistsBloodTypeCode();

            if (notExistsBloodTypeCode1 == notExistsBloodTypeCode2)
            {
                goto Start;
            }

            var newBloodTypes = new Collection <ReferenceBloodType>
            {
                new ReferenceBloodType {
                    Code = notExistsBloodTypeCode1, LongName = ""
                },
                new ReferenceBloodType {
                    Code = notExistsBloodTypeCode2, LongName = ""
                }
            };

            UnitOfWork.ReferenceBloodTypes.AddRange(newBloodTypes);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceBloodTypes.GetAll();

            Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceBloodTypes.Length + newBloodTypes.Count));
        }
Пример #2
0
        public void AddRange_TwoValidBloodTypesDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsBloodTypeCode = PreDefinedData.GetNotExistsBloodTypeCode();
            var newBloodTypes          = new Collection <ReferenceBloodType>
            {
                new ReferenceBloodType {
                    Id = int.MaxValue, Code = notExistsBloodTypeCode, LongName = ""
                },
                new ReferenceBloodType {
                    Id = int.MaxValue, Code = notExistsBloodTypeCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceBloodTypes.AddRange(newBloodTypes),
                        Throws.InvalidOperationException);
        }
Пример #3
0
        public void Add_ValidBloodTypeNotExists_FetchNewBloodType()
        {
            var notExistsBloodTypeCode = PreDefinedData.GetNotExistsBloodTypeCode();
            var newReferenceBloodType  = new ReferenceBloodType
            {
                Code     = notExistsBloodTypeCode,
                LongName = notExistsBloodTypeCode
            };

            UnitOfWork.ReferenceBloodTypes.Add(newReferenceBloodType);
            UnitOfWork.Complete();

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

            Assert.That(result, Is.Not.Null);

            AssertHelper.AreObjectsEqual(newReferenceBloodType, result);
        }
        public async Task Update_InvalidBloodType_HttpNotFound()
        {
            // Arrange
            var notExistsBloodTypeCode = PreDefinedData.GetNotExistsBloodTypeCode();
            var path = GetRelativePath(nameof(ReferenceBloodTypesController), int.MaxValue.ToString());
            var apiUpdatingBloodType = new ReferenceBloodTypeDto
            {
                Id       = int.MaxValue,
                Code     = notExistsBloodTypeCode,
                LongName = "Update Test"
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewBloodType()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceBloodTypesController));
            var notExistsBloodTypeCode = PreDefinedData.GetNotExistsBloodTypeCode();
            var newBloodTypeDto        = new ReferenceBloodTypeDto
            {
                Code         = notExistsBloodTypeCode,
                LongName     = "New",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newBloodTypeDto),
                                                      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 <ReferenceBloodTypeDto>(responseString);

            Assert.That(apiReturnedObject.Id, Is.GreaterThan(0));

            newBloodTypeDto.Id = apiReturnedObject.Id;
            AssertHelper.AreObjectsEqual(apiReturnedObject, newBloodTypeDto);
        }