public void AddRange_TwoValidCountries_CountIncreasedByTwo()
        {
Start:
            var notExistsCountryCode1 = PreDefinedData.GetNotExistsCountryCode();
            var notExistsCountryCode2 = PreDefinedData.GetNotExistsCountryCode();

            if (notExistsCountryCode1 == notExistsCountryCode2)
            {
                goto Start;
            }

            var newCountries = new Collection <ReferenceCountry>
            {
                new ReferenceCountry {
                    Code = notExistsCountryCode1, LongName = ""
                },
                new ReferenceCountry {
                    Code = notExistsCountryCode2, LongName = ""
                }
            };

            UnitOfWork.ReferenceCountries.AddRange(newCountries);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceCountries.GetAll();

            Assert.That(result.Count, Is.EqualTo(PreDefinedData.ReferenceCountries.Length + newCountries.Count));
        }
        public void AddRange_TwoValidCountriesDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsCountryCode = PreDefinedData.GetNotExistsCountryCode();
            var newCountries         = new Collection <ReferenceCountry>
            {
                new ReferenceCountry {
                    Id = int.MaxValue, Code = notExistsCountryCode, LongName = ""
                },
                new ReferenceCountry {
                    Id = int.MaxValue, Code = notExistsCountryCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceCountries.AddRange(newCountries),
                        Throws.InvalidOperationException);
        }
        public void Add_ValidCountryNotExists_FetchNewCountry()
        {
            var notExistsCountryCode = PreDefinedData.GetNotExistsCountryCode();
            var newReferenceCountry  = new ReferenceCountry
            {
                Code     = notExistsCountryCode,
                LongName = notExistsCountryCode
            };

            UnitOfWork.ReferenceCountries.Add(newReferenceCountry);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceCountries.Get(newReferenceCountry.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceCountry, result);
        }
        public async Task Update_InvalidCountry_HttpNotFound()
        {
            // Arrange
            var notExistsCountryCode = PreDefinedData.GetNotExistsCountryCode();
            var path = GetRelativePath(nameof(ReferenceCountriesController), int.MaxValue.ToString());
            var apiUpdatingCountry = new ReferenceCountryDto
            {
                Id       = int.MaxValue,
                Code     = notExistsCountryCode,
                LongName = "Update Test"
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewCountry()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceCountriesController));
            var notExistsCountryCode = PreDefinedData.GetNotExistsCountryCode();
            var newCountryDto        = new ReferenceCountryDto
            {
                Code         = notExistsCountryCode,
                LongName     = "New Country",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

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

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

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