Example #1
0
        private void ReloadTestData()
        {
            if (PersonTestData == default)
            {
                PersonTestData = new List <PersonEntity>();
            }
            if (AddressTestData == default)
            {
                AddressTestData = new List <AddressEntity>();
            }
            if (PersonAttributeTestData == default)
            {
                PersonAttributeTestData = new List <PersonAttributesEntity>();
            }

            PersonTestData.Clear();
            AddressTestData.Clear();
            PersonAttributeTestData.Clear();

            using (StreamReader file = File.OpenText("persontestdata.json"))
            {
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                PersonTestData.AddRange((List <PersonEntity>)serializer.Deserialize(file, typeof(List <PersonEntity>)));
            }
            using (StreamReader file = File.OpenText("addresstestdata.json"))
            {
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                AddressTestData.AddRange((List <AddressEntity>)serializer.Deserialize(file, typeof(List <AddressEntity>)));
            }
            using (StreamReader file = File.OpenText("personattributetestdata.json"))
            {
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                PersonAttributeTestData.AddRange((List <PersonAttributesEntity>)serializer.Deserialize(file, typeof(List <PersonAttributesEntity>)));
            }
        }
Example #2
0
 private Importer GetValidImporter(bool addedToAddressBook)
 {
     return(new Importer(Guid.NewGuid())
     {
         Address = AddressTestData.GetValidTestAddress(countryId),
         Contact = ContactTestData.GetValidTestContact(),
         BusinessName = "Test importer",
         IsAddedToAddressBook = addedToAddressBook
     });
 }
Example #3
0
        public static void Initialize(TestContext testContext)
        {
            IntergrationTestsSetup dbSetup = new IntergrationTestsSetup();

            using (var context = new PayrollContext(dbSetup.ContextOptions))
            {
                context.Country.AddRange(CountryTestData.InitialCountries());
                context.Province.AddRange(ProvinceTestData.InitialProvinces());
                context.Role.AddRange(RoleTestData.InitialRoles());
                context.Address.AddRange(AddressTestData.InitialAddresses());
                context.Organisation.AddRange(OrganisationTestData.InitialOrganisations());
                context.Account.AddRange(AccountTestData.InitialAccounts());

                context.SaveChanges();
            }
        }
Example #4
0
        private FacilityCollection GetValidFacilities(bool addedToAddressBook)
        {
            FacilityCollection result = new FacilityCollection();

            result.Facilities = new System.Collections.Generic.List <Facility>()
            {
                new Facility(Guid.NewGuid())
                {
                    Address              = AddressTestData.GetValidTestAddress(countryId),
                    Contact              = ContactTestData.GetValidTestContact(),
                    BusinessName         = "Test facility",
                    IsAddedToAddressBook = addedToAddressBook
                }
            };

            return(result);
        }
Example #5
0
        public async void CheckDistanceShouldCheckDistance()
        {
            // Arrange (create a moq repo and add a test address)
            var mockLogger       = new Mock <ILogger <AddressController> >();
            var mockAddressLogic = new Mock <IAddressLogic>();
            var options          = TestDbContext.TestDbInitalizer("CanCreate");

            using var database = TestDbContext.CreateTestDb(options);
            var mapper     = new Mapper();
            var logger     = new NullLogger <Address.DataAccess.DataAccess>();
            var dataAccess = new Address.DataAccess.DataAccess(database, mapper, logger);

            database.Add(AddressTestData.ValidAddress1());
            var test          = new AddressController(dataAccess, mockAddressLogic.Object, mockLogger.Object);
            var validAddress1 = new Address.Api.Models.AddressModel
            {
                Id      = new Guid("566e1a61-c283-4d33-9b9b-9a981393cf2b"),
                Street  = "1100 S W St",
                City    = "Arlington",
                State   = "Texas",
                Country = "US",
                ZipCode = "76010"
            };

            var validAddress2 = new Address.Api.Models.AddressModel
            {
                Id      = new Guid("2d9fe0e6-8029-483d-b5e9-c06cf2fad0d6"),
                Street  = "1560 Broadway Street",
                City    = "Boulder",
                State   = "Colorado",
                Country = "US",
                ZipCode = "80112"
            };
            var list = new List <Address.Api.Models.AddressModel>
            {
                validAddress1,
                validAddress2
            };

            // act (get check distance between addresses)
            var result = await test.IsInRange(list);

            // Assert correct address was receive

            Assert.False(result.Value);
        }
        public void Add_and_update_entities_preGenerated_and_onAddGeneratedProperties_Generates_two_audit_and_one_audit_metaDataEntity()
        {
            using (var transaction = Connection.BeginTransaction())
            {
                PersonEntity           personEntity;
                AddressEntity          addressEntity1;
                AddressEntity          addressEntity2;
                PersonAttributesEntity personAttributesEntity1;
                PersonAttributesEntity personAttributesEntity2;
                //Arrange and Act
                using (var context = CreateContext(transaction))
                {
                    personEntity = PersonTestData.FirstOrDefault();
                    context.Persons.Add(personEntity);
                    context.SaveChanges();
                    personEntity           = context.Persons.FirstOrDefault();
                    personEntity.FirstName = $"{personEntity.FirstName}Modified";
                    context.SaveChanges();

                    addressEntity1 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.Addresses.Add(addressEntity1);
                    addressEntity2 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.Addresses.Add(addressEntity2);
                    context.SaveChanges();
                    addressEntity1            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity1.Type);
                    addressEntity1.PostalCode = 12345;
                    addressEntity2            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity2.Type);
                    addressEntity2.PostalCode = 54321;
                    context.SaveChanges();

                    personAttributesEntity1 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.PersonAttributes.Add(personAttributesEntity1);
                    personAttributesEntity2 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.PersonAttributes.Add(personAttributesEntity2);
                    context.SaveChanges();
                    personAttributesEntity1                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity1.Id);
                    personAttributesEntity2                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity2.Id);
                    personAttributesEntity1.DummyString    = "cahangingDummyString";
                    personAttributesEntity1.Attribute      = AttributeType.Profession;
                    personAttributesEntity1.AttributeValue = "Graphic Designer";
                    context.Remove(personAttributesEntity2);
                    context.SaveChanges();
                }

                using (var context = CreateContext(transaction))
                {
                    //Assert
                    List <AuditMetaDataEntity> auditMetaDatas = context.AuditMetaDatas.Include(amd => amd.AuditChanges).ToList();
                    List <AuditEntity>         audits         = context.Audits.Include(a => a.AuditMetaData).ToList();

                    Assert.Equal(5, auditMetaDatas.Count);
                    Assert.Equal(10, audits.Count);

                    /************************************************************************************************************************/

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "PersonEntity" && x.Schema == default && x.Table == "Persons" && x.SchemaTable == "Persons" &&
                                   x.ReadablePrimaryKey == "Id=caf3feb5-730e-40a3-9610-404a17b0deba" &&
                                   x.HashPrimaryKey == "Id=caf3feb5-730e-40a3-9610-404a17b0deba".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    Assert.Equal(2, auditMetaDatas.Count(x => x.DisplayName == "PersonAttributesEntity" && x.Schema == default && x.Table == "PersonAttributes" && x.SchemaTable == "PersonAttributes" &&
                                                         x.AuditChanges.Count == 2));

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "AddressEntity" && x.Schema == default && x.Table == "Addresses" && x.SchemaTable == "Addresses" &&
                                   x.ReadablePrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home" &&
                                   x.HashPrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    Assert.Single(auditMetaDatas,
                                  (x => x.DisplayName == "AddressEntity" && x.Schema == default && x.Table == "Addresses" && x.SchemaTable == "Addresses" &&
                                   x.ReadablePrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work" &&
                                   x.HashPrimaryKey == "PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work".ToGuidHash() &&
                                   x.AuditChanges.Count == 2));

                    /************************************************************************************************************************/

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"Id\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"FirstName\":\"Ofella\",\"Gender\":1,\"LastName\":\"Andrichuk\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"FirstName\":\"OfellaModified\"}" &&
                                   x.OldValues == "{\"FirstName\":\"Ofella\"}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"PersonId\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"Type\":1,\"City\":\"Azteca\",\"HouseNumber\":\"844\",\"PostalCode\":50188,\"Street\":\"Vahlen\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Added &&
                                   x.NewValues == "{\"PersonId\":\"caf3feb5-730e-40a3-9610-404a17b0deba\",\"Type\":2,\"City\":\"Tawun\",\"HouseNumber\":\"7\",\"PostalCode\":32921,\"Street\":\"Welch\"}" &&
                                   x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"PostalCode\":54321}" &&
                                   x.OldValues == "{\"PostalCode\":50188}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"PostalCode\":12345}" &&
                                   x.OldValues == "{\"PostalCode\":32921}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Equal(2, audits.Count(x => x.AuditMetaData.DisplayName == "PersonAttributesEntity" && x.Id != default && x.EntityState == EntityState.Added &&
                                                 x.OldValues == default && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Modified &&
                                   x.NewValues == "{\"Attribute\":2,\"AttributeValue\":\"Graphic Designer\"}" &&
                                   x.OldValues == "{\"Attribute\":1,\"AttributeValue\":\"Married\"}" && x.ByUser != default && x.DateTimeOffset != default));

                    Assert.Single(audits,
                                  (x => x.AuditMetaData != default && x.Id != default && x.EntityState == EntityState.Deleted &&
                                   x.NewValues == default && x.ByUser != default && x.DateTimeOffset != default));
                }
            }
        }
        public void Add_and_update_entities_preGenerated_and_onAddGeneratedProperties_Generates_two_audit_and_one_audit_metaDataEntity()
        {
            using (var transaction = Connection.BeginTransaction())
            {
                PersonEntity           personEntity;
                AddressEntity          addressEntity1;
                AddressEntity          addressEntity2;
                PersonAttributesEntity personAttributesEntity1;
                PersonAttributesEntity personAttributesEntity2;
                //Arrange and Act
                using (var context = CreateContext(transaction))
                {
                    personEntity = PersonTestData.FirstOrDefault();
                    context.Persons.Add(personEntity);
                    context.SaveChanges();
                    personEntity           = context.Persons.FirstOrDefault();
                    personEntity.FirstName = $"{personEntity.FirstName}Modified";
                    context.SaveChanges();

                    addressEntity1 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.Addresses.Add(addressEntity1);
                    addressEntity2 = AddressTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.Addresses.Add(addressEntity2);
                    context.SaveChanges();
                    addressEntity1            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity1.Type);
                    addressEntity1.PostalCode = 12345;
                    addressEntity2            = context.Addresses.FirstOrDefault(x => x.PersonId == personEntity.Id && x.Type == addressEntity2.Type);
                    addressEntity2.PostalCode = 54321;
                    context.SaveChanges();

                    personAttributesEntity1 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(0);
                    context.PersonAttributes.Add(personAttributesEntity1);
                    personAttributesEntity2 = PersonAttributeTestData.Where(x => x.PersonId == personEntity.Id).ElementAt(1);
                    context.PersonAttributes.Add(personAttributesEntity2);
                    context.SaveChanges();
                    personAttributesEntity1                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity1.Id);
                    personAttributesEntity2                = context.PersonAttributes.FirstOrDefault(x => x.Id == personAttributesEntity2.Id);
                    personAttributesEntity1.DummyString    = "cahangingDummyString";
                    personAttributesEntity1.Attribute      = AttributeType.Profession;
                    personAttributesEntity1.AttributeValue = "Graphic Designer";
                    context.Remove(personAttributesEntity2);
                    context.SaveChanges();
                }

                using (var context = CreateContext(transaction))
                {
                    //Assert
                    List <AuditMetaDataEntity> auditMetaDatas = context.AuditMetaDatas.Include(amd => amd.AuditChanges).ToList();
                    List <AuditEntity>         audits         = context.Audits.Include(a => a.AuditMetaData).ToList();

                    Assert.Equal(5, auditMetaDatas.Count);
                    Assert.Equal(10, audits.Count);

                    /************************************************************************************************************************/

                    Assert.Equal(2, auditMetaDatas[0].AuditChanges.Count);
                    Assert.Equal("AddressEntity", auditMetaDatas[0].DisplayName);
                    Assert.Null(auditMetaDatas[0].Schema);
                    Assert.Equal("Addresses", auditMetaDatas[0].Table);
                    Assert.Equal("Addresses", auditMetaDatas[0].SchemaTable);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home", auditMetaDatas[0].ReadablePrimaryKey);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Home".ToGuidHash(), auditMetaDatas[0].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[1].AuditChanges.Count);
                    Assert.Equal("PersonEntity", auditMetaDatas[1].DisplayName);
                    Assert.Null(auditMetaDatas[1].Schema);
                    Assert.Equal("Persons", auditMetaDatas[1].Table);
                    Assert.Equal("Persons", auditMetaDatas[1].SchemaTable);
                    Assert.Equal("Id=caf3feb5-730e-40a3-9610-404a17b0deba", auditMetaDatas[1].ReadablePrimaryKey);
                    Assert.Equal("Id=caf3feb5-730e-40a3-9610-404a17b0deba".ToGuidHash(), auditMetaDatas[1].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[2].AuditChanges.Count);
                    Assert.Equal("AddressEntity", auditMetaDatas[2].DisplayName);
                    Assert.Null(auditMetaDatas[2].Schema);
                    Assert.Equal("Addresses", auditMetaDatas[2].Table);
                    Assert.Equal("Addresses", auditMetaDatas[2].SchemaTable);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work", auditMetaDatas[2].ReadablePrimaryKey);
                    Assert.Equal("PersonId=caf3feb5-730e-40a3-9610-404a17b0deba,Type=Work".ToGuidHash(), auditMetaDatas[2].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[3].AuditChanges.Count);
                    Assert.Equal("PersonAttributesEntity", auditMetaDatas[3].DisplayName);
                    Assert.Null(auditMetaDatas[3].Schema);
                    Assert.Equal("PersonAttributes", auditMetaDatas[3].Table);
                    Assert.Equal("PersonAttributes", auditMetaDatas[3].SchemaTable);
                    Assert.Equal("Id=2", auditMetaDatas[3].ReadablePrimaryKey);
                    Assert.Equal("Id=2".ToGuidHash(), auditMetaDatas[3].HashPrimaryKey);

                    Assert.Equal(2, auditMetaDatas[4].AuditChanges.Count);
                    Assert.Equal("PersonAttributesEntity", auditMetaDatas[4].DisplayName);
                    Assert.Null(auditMetaDatas[4].Schema);
                    Assert.Equal("PersonAttributes", auditMetaDatas[4].Table);
                    Assert.Equal("PersonAttributes", auditMetaDatas[4].SchemaTable);
                    Assert.Equal("Id=1", auditMetaDatas[4].ReadablePrimaryKey);
                    Assert.Equal("Id=1".ToGuidHash(), auditMetaDatas[4].HashPrimaryKey);

                    /************************************************************************************************************************/

                    Assert.NotNull(audits[0].AuditMetaData);
                    Assert.NotEqual(default, audits[0].Id);