コード例 #1
0
        public void AddRange_TwoValidStateProvincesDuplicated_ThrowsInvalidOperationException()
        {
            var notExistsStateProvinceCode = PreDefinedData.GetNotExistsStateProvinceCode();
            var newStateProvinces          = new Collection <ReferenceStateProvince>
            {
                new ReferenceStateProvince {
                    Id = int.MaxValue, CountryId = 1, Code = notExistsStateProvinceCode, LongName = ""
                },
                new ReferenceStateProvince {
                    Id = int.MaxValue, CountryId = 1, Code = notExistsStateProvinceCode, LongName = ""
                }
            };

            Assert.That(() => UnitOfWork.ReferenceStateProvinces.AddRange(newStateProvinces),
                        Throws.InvalidOperationException);
        }
コード例 #2
0
        public async Task Delete_ValidHairColor_HttpNoContent()
        {
            // Arrange
            var randomHairColorId = PreDefinedData.GetRandomHairColorId();
            var path = GetRelativePath(nameof(ReferenceHairColorsController), randomHairColorId.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));
        }
コード例 #3
0
        public void Add_ValidEthnicGroupNotExists_FetchNewEthnicGroup()
        {
            var notExistsEthnicGroupCode = PreDefinedData.GetNotExistsEthnicGroupCode();
            var newReferenceEthnicGroup  = new ReferenceEthnicGroup
            {
                Code     = notExistsEthnicGroupCode,
                LongName = notExistsEthnicGroupCode
            };

            UnitOfWork.ReferenceEthnicGroups.Add(newReferenceEthnicGroup);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceEthnicGroups.Get(newReferenceEthnicGroup.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceEthnicGroup, result);
        }
コード例 #4
0
        public void RemoveRange_TwoValidEyeColorsDuplicated_ThrowsInvalidOperationException()
        {
            var randomEyeColorId = PreDefinedData.GetRandomEyeColorId();
            var randomEyeColor   = UnitOfWork.ReferenceEyeColors.Get(randomEyeColorId);

            var existingEyeColors = new Collection <ReferenceEyeColor>
            {
                new ReferenceEyeColor {
                    Id = randomEyeColor.Id, Code = randomEyeColor.Code
                },
                new ReferenceEyeColor {
                    Id = randomEyeColor.Id, Code = randomEyeColor.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceEyeColors.RemoveRange(existingEyeColors),
                        Throws.InvalidOperationException);
        }
コード例 #5
0
        public void Add_ValidEyeColorNotExists_FetchNewEyeColor()
        {
            var notExistsEyeColorCode = PreDefinedData.GetNotExistsEyeColorCode();
            var newReferenceEyeColor  = new ReferenceEyeColor
            {
                Code     = notExistsEyeColorCode,
                LongName = notExistsEyeColorCode
            };

            UnitOfWork.ReferenceEyeColors.Add(newReferenceEyeColor);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceEyeColors.Get(newReferenceEyeColor.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceEyeColor, result);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void RemoveRange_TwoValidEthnicGroupsDuplicated_ThrowsInvalidOperationException()
        {
            var randomEthnicGroupId = PreDefinedData.GetRandomEthnicGroupId();
            var randomEthnicGroup   = UnitOfWork.ReferenceEthnicGroups.Get(randomEthnicGroupId);

            var existingEthnicGroups = new Collection <ReferenceEthnicGroup>
            {
                new ReferenceEthnicGroup {
                    Id = randomEthnicGroup.Id, Code = randomEthnicGroup.Code
                },
                new ReferenceEthnicGroup {
                    Id = randomEthnicGroup.Id, Code = randomEthnicGroup.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceEthnicGroups.RemoveRange(existingEthnicGroups),
                        Throws.InvalidOperationException);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public void RemoveRange_TwoValidNameSuffixesDuplicated_ThrowsInvalidOperationException()
        {
            var randomNameSuffixId = PreDefinedData.GetRandomNameSuffixId();
            var randomNameSuffix   = UnitOfWork.ReferenceNameSuffixes.Get(randomNameSuffixId);

            var existingNameSuffixes = new Collection <ReferenceNameSuffix>
            {
                new ReferenceNameSuffix {
                    Id = randomNameSuffix.Id, Code = randomNameSuffix.Code
                },
                new ReferenceNameSuffix {
                    Id = randomNameSuffix.Id, Code = randomNameSuffix.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceNameSuffixes.RemoveRange(existingNameSuffixes),
                        Throws.InvalidOperationException);
        }
コード例 #11
0
        public void Add_ValidNameSuffixNotExists_FetchNewNameSuffix()
        {
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var newReferenceNameSuffix  = new ReferenceNameSuffix
            {
                Code     = notExistsNameSuffixCode,
                LongName = notExistsNameSuffixCode
            };

            UnitOfWork.ReferenceNameSuffixes.Add(newReferenceNameSuffix);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceNameSuffixes.Get(newReferenceNameSuffix.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceNameSuffix, result);
        }
コード例 #12
0
        public void RemoveRange_TwoValidReligionsDuplicated_ThrowsInvalidOperationException()
        {
            var randomReligionId = PreDefinedData.GetRandomReligionId();
            var randomReligion   = UnitOfWork.ReferenceReligions.Get(randomReligionId);

            var existingReligions = new Collection <ReferenceReligion>
            {
                new ReferenceReligion {
                    Id = randomReligion.Id, Code = randomReligion.Code
                },
                new ReferenceReligion {
                    Id = randomReligion.Id, Code = randomReligion.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceReligions.RemoveRange(existingReligions),
                        Throws.InvalidOperationException);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public void RemoveRange_TwoValidCountriesDuplicated_ThrowsInvalidOperationException()
        {
            var randomCountryId = PreDefinedData.GetRandomCountryId();
            var randomCountry   = UnitOfWork.ReferenceCountries.Get(randomCountryId);

            var existingCountries = new Collection <ReferenceCountry>
            {
                new ReferenceCountry {
                    Id = randomCountry.Id, Code = randomCountry.Code
                },
                new ReferenceCountry {
                    Id = randomCountry.Id, Code = randomCountry.Code
                }
            };

            Assert.That(() => UnitOfWork.ReferenceCountries.RemoveRange(existingCountries),
                        Throws.InvalidOperationException);
        }
コード例 #15
0
        public void Add_ValidStateProvinceNotExists_FetchNewStateProvince()
        {
            var notExistsStateProvinceCode = PreDefinedData.GetNotExistsStateProvinceCode();
            var newReferenceStateProvince  = new ReferenceStateProvince
            {
                CountryId = 1,
                Code      = notExistsStateProvinceCode,
                LongName  = notExistsStateProvinceCode
            };

            UnitOfWork.ReferenceStateProvinces.Add(newReferenceStateProvince);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceStateProvinces.Get(newReferenceStateProvince.Id);

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

            AssertHelper.AreObjectsEqual(newReferenceStateProvince, result);
        }
コード例 #16
0
        public async Task Update_MalformedPayload_HttpBadRequest()
        {
            // Arrange
            var randomHairColorId = PreDefinedData.GetRandomHairColorId();
            var path = GetRelativePath(nameof(ReferenceHairColorsController), randomHairColorId.ToString());
            var apiUpdatingHairColor = new ReferenceHairColorDto
            {
                Id = randomHairColorId
                     // Code is required, keep it missing
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
コード例 #17
0
        public async Task Update_InvalidHairColor_HttpNotFound()
        {
            // Arrange
            var notExistsHairColorCode = PreDefinedData.GetNotExistsHairColorCode();
            var path = GetRelativePath(nameof(ReferenceHairColorsController), int.MaxValue.ToString());
            var apiUpdatingHairColor = new ReferenceHairColorDto
            {
                Id       = int.MaxValue,
                Code     = notExistsHairColorCode,
                LongName = "Update"
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
コード例 #18
0
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewStateProvince()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceStateProvincesController));
            var notExistsStateProvinceCode = PreDefinedData.GetNotExistsStateProvinceCode();
            var newStateProvinceDto        = new ReferenceStateProvinceDto
            {
                CountryCode  = "US",
                Code         = notExistsStateProvinceCode,
                LongName     = "New StateProvince",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

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

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

            newStateProvinceDto.Id = apiReturnedObject.Id;
            AssertHelper.AreObjectsEqual(apiReturnedObject, newStateProvinceDto);
        }
コード例 #19
0
        public async Task Create_ExistingHairColor_HttpConflict()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceHairColorsController));
            var randomHairColorId = PreDefinedData.GetRandomHairColorId();
            var randomHairColor   = PreDefinedData.ReferenceHairColors[randomHairColorId - 1];

            var newHairColorDto = new ReferenceHairColorDto
            {
                Code        = randomHairColor.Code,
                LongName    = "Create",
                CreatedDate = DateTime.UtcNow
            };

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

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict));
        }
コード例 #20
0
 public abstract string Generate(IElement element, PreDefinedData preDefinedData);
コード例 #21
0
 public override string Generate(IElement element, PreDefinedData preDefinedData)
 {
     return(GetClickableMethodScript(element.GetTypeName()) + ToUpperFirstLetter(element.GetValidIdentifier()) +
            "();");
 }