Exemplo n.º 1
0
        public void AddRange_TwoValidGenders_CountIncreasedByTwo()
        {
Start:
            var notExistsGenderCode1 = PreDefinedData.GetNotExistsGenderCode();
            var notExistsGenderCode2 = PreDefinedData.GetNotExistsGenderCode();

            if (notExistsGenderCode1 == notExistsGenderCode2)
            {
                goto Start;
            }

            var newGenders = new Collection <ReferenceGender>
            {
                new ReferenceGender {
                    Code = notExistsGenderCode1, LongName = ""
                },
                new ReferenceGender {
                    Code = notExistsGenderCode2, LongName = ""
                }
            };

            UnitOfWork.ReferenceGenders.AddRange(newGenders);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceGenders.GetAll();

            Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceGenders.Length + newGenders.Count));
        }
Exemplo n.º 2
0
        public void AddRange_TwoValidGendersDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsGenderCode = PreDefinedData.GetNotExistsGenderCode();
            var newGenders          = new Collection <ReferenceGender>
            {
                new ReferenceGender {
                    Id = int.MaxValue, Code = notExistsGenderCode, LongName = ""
                },
                new ReferenceGender {
                    Id = int.MaxValue, Code = notExistsGenderCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceGenders.AddRange(newGenders),
                        Throws.InvalidOperationException);
        }
Exemplo n.º 3
0
        public void Add_ValidGenderNotExists_FetchNewGender()
        {
            var notExistsGenderCode = PreDefinedData.GetNotExistsGenderCode();
            var newReferenceGender  = new ReferenceGender
            {
                Code     = notExistsGenderCode,
                LongName = notExistsGenderCode
            };

            UnitOfWork.ReferenceGenders.Add(newReferenceGender);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceGenders.Get(newReferenceGender.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceGender, result);
        }
        public async Task Update_InvalidGender_HttpNotFound()
        {
            // Arrange
            var notExistsGenderCode = PreDefinedData.GetNotExistsGenderCode();
            var path = GetRelativePath(nameof(ReferenceGendersController), int.MaxValue.ToString());
            var apiUpdatingGender = new ReferenceGenderDto
            {
                Id       = int.MaxValue,
                Code     = notExistsGenderCode,
                LongName = "Update"
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewGender()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceGendersController));
            var notExistsGenderCode = PreDefinedData.GetNotExistsGenderCode();
            var newGenderDto        = new ReferenceGenderDto
            {
                Code         = notExistsGenderCode,
                LongName     = "New",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

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

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

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