Ejemplo n.º 1
0
        [TestMethod] public void CreateWithRegionInfoTest()
        {
            var i = new RegionInfo("ee-EE");

            o = CountryFactory.Create(i);
            validateResults(i.ThreeLetterISORegionName, i.DisplayName, i.TwoLetterISORegionName);
        }
        //------------------------------------------------------ 

        private static void CreateCountryInternalDatabase(ApplicationDbContext dbContext)
        {
            _country1 = CountryFactory.Create(
               "NL",
               "Nederland",
               1,
               10);

            _country2 = CountryFactory.Create(
                "BE",
                "België",
                2,
                20);

            _country3 = CountryFactory.Create(
                "US",
                "United States",
                3,
                30);

            _country4 = CountryFactory.Create(
               "DE",
               "Duitsland",
               4,
               44);

            var countryList = new List<Country> { _country1, _country2, _country3, _country4 };
            foreach (var country in countryList)
            {
                dbContext.Countries.Add(country); // voeg toe aan intern-memory DB
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public StateOfImportValidatorTests()
        {
            var countryRepo   = A.Fake <ICountryRepository>();
            var caRepo        = A.Fake <ICompetentAuthorityRepository>();
            var exitPointRepo = A.Fake <IEntryOrExitPointRepository>();

            var uk   = CountryFactory.Create(ukId, "United Kingdom");
            var ukCa = CompetentAuthorityFactory.Create(ukCaId, uk);

            var france   = CountryFactory.Create(Guid.NewGuid(), "France");
            var franceCa = CompetentAuthorityFactory.Create(nonUkCaId, france);

            A.CallTo(() => countryRepo.GetUnitedKingdomId()).Returns(ukId);

            A.CallTo(() => caRepo.GetById(ukCaId)).Returns(ukCa);
            A.CallTo(() => caRepo.GetById(nonUkCaId)).Returns(franceCa);

            var dover  = EntryOrExitPointFactory.Create(ukEntryPointId, uk);
            var calais = EntryOrExitPointFactory.Create(nonUkEntryPointId, france);

            A.CallTo(() => exitPointRepo.GetById(ukEntryPointId)).Returns(dover);
            A.CallTo(() => exitPointRepo.GetById(nonUkEntryPointId)).Returns(calais);

            validator = new StateOfImportValidator(countryRepo, caRepo, exitPointRepo);
        }
        public GetExitCustomsOfficeAddDataByNotificationIdTests()
        {
            context = new TestIwsContext();
            var repository = A.Fake <ITransportRouteRepository>();

            country           = CountryFactory.Create(new Guid("05C21C57-2F39-4A15-A09A-5F38CF139C05"));
            exitCustomsOffice = new ExitCustomsOffice("any name", "any address", country);

            notification = NotificationApplicationFactory.Create(TestIwsContext.UserId, NotificationType.Recovery,
                                                                 UKCompetentAuthority.England, 500);

            transport = new TransportRoute(NotificationId);

            EntityHelper.SetEntityId(notification, NotificationId);

            context.Countries.Add(country);
            context.NotificationApplications.Add(notification);
            context.TransportRoutes.Add(transport);

            A.CallTo(() => repository.GetByNotificationId(NotificationId)).Returns(transport);

            handler = new GetExitCustomsOfficeAddDataByNotificationIdHandler(repository,
                                                                             new CustomsOfficeExitMap(context,
                                                                                                      new CountryMap(),
                                                                                                      new CustomsOfficeMap(new CountryMap())));
        }
Ejemplo n.º 5
0
        public void CreateCaseNullTest()
        {
            var factory = new CountryFactory();
            var r       = new Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Root();

            Assert.ThrowsException <Exception>(() => factory.Create(r));
        }
        public GetCompetentAuthoritiesAndEntryOrExitPointsByCountryIdHandlerTests()
        {
            var entryOrExitPointRepository = A.Fake <IEntryOrExitPointRepository>();

            var competentAuthorityMapper = new CompetentAuthorityMap();
            var entryOrExitPointMapper   = new EntryOrExitPointMap();

            var countryWithData   = CountryFactory.Create(countryWithDataId);
            var countryWithNoData = CountryFactory.Create(countryWithNoDataId);

            var competentAuthorities = new[]
            {
                CompetentAuthorityFactory.Create(new Guid("C74A75B9-C338-4330-A43A-3AAF3B8FA5E7"), countryWithData),
                CompetentAuthorityFactory.Create(new Guid("B076AF57-83EB-4F99-BDE6-859CC2B35FBE"), countryWithData)
            };

            A.CallTo(() => entryOrExitPointRepository.GetForCountry(countryWithDataId)).Returns(new[]
            {
                EntryOrExitPointFactory.Create(new Guid("B054CA23-18D3-4E4E-A2B1-F92B7503919A"), countryWithData),
                EntryOrExitPointFactory.Create(new Guid("9F0DC969-8224-4FEC-BD0D-B90B70378323"), countryWithData)
            });

            var repository = A.Fake <ICompetentAuthorityRepository>();

            A.CallTo(() => repository.GetCompetentAuthorities(countryWithDataId)).Returns(competentAuthorities);

            handler = new GetCompetentAuthoritiesAndEntryOrExitPointsByCountryIdHandler(entryOrExitPointMapper, competentAuthorityMapper, repository, entryOrExitPointRepository);
        }
Ejemplo n.º 7
0
        public NotificationTransportRouteTests()
        {
            this.transportRoute = new TransportRoute(Guid.Empty);

            guids = new List <Guid>
            {
                new Guid("D8DB53F9-D3CB-498D-B044-7A67B94EE4E4"),
                new Guid("1D3A7A18-F345-4201-81AA-8FC8A4029F4E"),
                new Guid("596E6BE3-D0C1-4C17-AF75-BFCDBD972627"),
                new Guid("208EA94D-638B-4724-9272-DF1383FF9452"),
                new Guid("DEDAA6F6-CA6D-486E-B0B8-254A477E697F"),
                new Guid("4C7EEA30-510E-45BD-8DBB-3EC1AF5E563A"),
                new Guid("8B87B87D-43D0-4BBE-8E2C-8EC84C983A42"),
                new Guid("40E44905-4CDE-4470-8E8B-527EE65C65DC"),
                new Guid("58E18F1C-5A4A-4E2E-869F-72D9C1512FE8")
            };

            countries = guids.Select(g => CountryFactory.Create(g)).ToList();

            transitStates = new List <TransitState>();
            for (int i = 0; i < countries.Count - 1; i++)
            {
                var c = countries[i];
                transitStates.Add(new TransitState(c,
                                                   CompetentAuthorityFactory.Create(guids[i], c),
                                                   EntryOrExitPointFactory.Create(guids[i], c),
                                                   EntryOrExitPointFactory.Create(guids[i + 1], c), i + 1));
                ObjectInstantiator <TransitState> .SetProperty(x => x.Id, guids[i], transitStates[i]);
            }

            this.validator = A.Fake <ITransportRouteValidator>();
        }
        public GetCompetentAuthoritiesAndEntryPointsByCountryIdHandlerTests()
        {
            entryOrExitPointRepository                = A.Fake <IEntryOrExitPointRepository>();
            intraCountryExportAllowedRepository       = A.Fake <IIntraCountryExportAllowedRepository>();
            unitedKingdomCompetentAuthorityRepository = A.Fake <IUnitedKingdomCompetentAuthorityRepository>();
            var iwsContext = new TestIwsContext();

            var countryWithData      = CountryFactory.Create(countryWithDataId);
            var unitedKingdomCountry = CountryFactory.Create(unitedKingdomCountryId);
            var countryWithNoData    = CountryFactory.Create(countryWithNoDataId);

            competentAuthorities = new[]
            {
                CompetentAuthorityFactory.Create(new Guid("67D2B3B5-298A-4BB5-901C-0C0C80097242"), unitedKingdomCountry),
                CompetentAuthorityFactory.Create(new Guid("5E7CA40F-D7B5-49C3-8850-694D36D52C94"), countryWithData),
                CompetentAuthorityFactory.Create(new Guid("DFD98B0D-F255-4BA0-96A5-527DE9F973E3"), countryWithData)
            };

            A.CallTo(() => unitedKingdomCompetentAuthorityRepository.GetAll()).Returns(new[]
            {
                new TestableUnitedKingdomCompetentAuthority(1, competentAuthorities[0], "something", null)
            });

            var competentAuthorityMapper = new CompetentAuthorityMap();
            var entryOrExitPointMapper   = new EntryOrExitPointMap();

            A.CallTo(() => entryOrExitPointRepository.GetForCountry(countryWithDataId)).Returns(new[]
            {
                EntryOrExitPointFactory.Create(new Guid("FC012C3E-4252-4D62-A8A2-D46DE0FA93B9"), countryWithData),
                EntryOrExitPointFactory.Create(new Guid("9699CC16-6EF1-4889-9598-F4B0511A2038"), countryWithData)
            });

            A.CallTo(() => intraCountryExportAllowedRepository.GetImportCompetentAuthorities(UKCompetentAuthority.England)).Returns(new[]
            {
                new TestableIntraCountryExportAllowed
                {
                    ExportCompetentAuthority   = UKCompetentAuthority.England,
                    ImportCompetentAuthorityId = competentAuthorities[1].Id
                }
            });

            repository = A.Fake <ICompetentAuthorityRepository>();

            A.CallTo(() => repository.GetCompetentAuthorities(countryWithDataId)).Returns(competentAuthorities);

            ids = new Guid[]
            {
                competentAuthorities[1].Id
            };

            A.CallTo(repository).Where(call => call.Method.Name == "GetByIds")
            .WithReturnType <CompetentAuthority[]>()
            .Returns(competentAuthorities);

            handler = new GetCompetentAuthoritiesAndEntryPointsByCountryIdHandler(entryOrExitPointMapper, competentAuthorityMapper, repository, entryOrExitPointRepository, intraCountryExportAllowedRepository, iwsContext, unitedKingdomCompetentAuthorityRepository);
        }
Ejemplo n.º 9
0
        public void SetAnnexMessageTest()
        {
            var statesList = new List <TransitState>();

            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "one"), "short name"));
            var vm = new TransitStateViewModel(statesList);

            vm.SetAnnexMessage(6);

            Assert.Equal("See Annex 6", vm.AnnexMessage);
        }
Ejemplo n.º 10
0
        public AddressBuilderTests()
        {
            countryRepository = A.Fake <ICountryRepository>();

            var uk     = CountryFactory.Create(ukId, "United Kingdom");
            var france = CountryFactory.Create(nonUkId, "France");

            A.CallTo(() => countryRepository.GetById(ukId)).Returns(uk);
            A.CallTo(() => countryRepository.GetById(nonUkId)).Returns(france);

            addressBuilder = new AddressBuilder(countryRepository);
        }
Ejemplo n.º 11
0
        public NotificationTransitStateTests()
        {
            transportRoute = new TransportRoute(AnyGuid);

            var firstCountry  = CountryFactory.Create(new Guid("A5E60A6E-D237-461F-8737-FE8190CEC1BC"));
            var secondCountry = CountryFactory.Create(new Guid("DB611B2D-2EF2-42AA-8857-B4B953D91767"));
            var thirdCountry  = CountryFactory.Create(new Guid("C5C282CE-D4A6-4F81-BCD9-2518098D1D85"));

            transportRoute.AddTransitStateToNotification(TransitStateFactory.Create(FirstTransitStateId, firstCountry, 1));
            transportRoute.AddTransitStateToNotification(TransitStateFactory.Create(SecondTransitStateId, secondCountry, 2));
            transportRoute.AddTransitStateToNotification(TransitStateFactory.Create(ThirdTransitStateId, thirdCountry, 3));
        }
Ejemplo n.º 12
0
        public void OneStateDisplaysInMiddleOnFormTest()
        {
            var statesList = new List <TransitState>();

            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "one"), "short name"));

            var vm = new TransitStateViewModel(statesList);

            Assert.Equal(string.Empty, vm.AnnexMessage);
            Assert.Equal("one", vm.MiddleCountry);
            Assert.Equal(string.Empty, vm.LeftCountry);
            Assert.Equal(string.Empty, vm.RightCountry);
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind(properties)] CountryView c)
        {
            await validateId(c.Alpha3Code, ModelState);

            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            var o = CountryFactory.Create(c.Alpha3Code, c.Name, c.Alpha2Code, c.ValidFrom,
                                          c.ValidTo);
            await reporitory.AddObject(o);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        public void OneStateDisplaysInAnnexIfPointNameLengthGreaterThan12Test()
        {
            var statesList = new List <TransitState>();

            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "one"), "long name >12"));

            var vm = new TransitStateViewModel(statesList);

            vm.SetAnnexMessage(6);

            Assert.Equal("See Annex 6", vm.AnnexMessage);
            Assert.Equal(string.Empty, vm.MiddleCountry);
            Assert.Equal(string.Empty, vm.LeftCountry);
            Assert.Equal(string.Empty, vm.RightCountry);
            Assert.Equal(1, vm.TransitStateDetails.Count);
            Assert.Equal("one", vm.TransitStateDetails[0].Country);
        }
Ejemplo n.º 15
0
        public AddImportAddressBookEntryHandlerTests()
        {
            context                           = new TestIwsContext();
            userContext                       = A.Fake <IUserContext>();
            addressBookRepository             = A.Fake <IAddressBookRepository>();
            draftImportNotificationRepository = A.Fake <IDraftImportNotificationRepository>();
            message                           = new AddImportAddressBookEntry(notificationId);

            var country = CountryFactory.Create(countryId);

            context.Countries.Add(country);

            addressBook = A.Fake <AddressBook>();

            A.CallTo(() => userContext.UserId).Returns(userId);
            A.CallTo(() => addressBookRepository.GetAddressBookForUser(userContext.UserId, AddressRecordType.Carrier)).Returns(addressBook);
        }
Ejemplo n.º 16
0
        public GetOrganisationDetailsByUserHandlerTests()
        {
            userContext = A.Fake <IUserContext>();
            A.CallTo(() => userContext.UserId).Returns(userId);

            context = new TestIwsContext(userContext);

            var country = CountryFactory.Create(new Guid("05C21C57-2F39-4A15-A09A-5F38CF139C05"));

            context.Countries.Add(country);

            context.Organisations.Add(GetOrganisation());

            context.Users.Add(GetUser());

            message = new GetOrganisationDetailsByUser();
            handler = new GetOrganisationDetailsByUserHandler(context, userContext);
        }
Ejemplo n.º 17
0
        public void CreateTest()
        {
            var factory = new CountryFactory();
            var r       = new Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Root();

            r.latlng = new List <double>();
            r.latlng.Add(1);
            r.latlng.Add(2);
            r.currencies = new List <Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Currency>();
            r.currencies.Add(Moq.Mock.Of <Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Currency>());
            r.languages = new List <Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Language>();
            r.languages.Add(Moq.Mock.Of <Infraestructure.ExternalAPI.SerializedObjects.DataCountry.Language>());
            r.timezones = new List <string>();
            r.timezones.Add("");

            var f = factory.Create(r);

            Assert.AreEqual(r.alpha2Code, f.Alpha2Code);
        }
        public UpdateOrganisationDetailsHandlerTests()
        {
            userContext = A.Fake <IUserContext>();
            A.CallTo(() => userContext.UserId).Returns(userId);

            context = new TestIwsContext(userContext);

            var country = CountryFactory.Create(countryId);

            context.Countries.Add(country);

            address = new Address(address1, address2, town, null, postcode, country.Name);

            context.Organisations.Add(GetOrganisation());

            context.Users.Add(GetUser());

            handler = new UpdateOrganisationDetailsHandler(context, userContext);
        }
Ejemplo n.º 19
0
        public static void Initialize(ApplicationDbContext c)
        {
            c.Database.EnsureCreated();
            if (c.Countries.Any())
            {
                return;
            }
            var regions = SystemRegionInfo.GetRegionsList();

            foreach (var r in regions)
            {
                if (!SystemRegionInfo.IsCountry(r))
                {
                    continue;
                }
                var e = CountryFactory.Create(r);
                c.Countries.Add(e.Data);
            }
            c.SaveChanges();
        }
Ejemplo n.º 20
0
        public RemoveTransitStateForNotificationHandlerTests()
        {
            var userContext = A.Fake <IUserContext>();

            A.CallTo(() => userContext.UserId).Returns(Guid.Empty);
            context = new TestIwsContext(userContext);

            var notification = NotificationApplicationFactory.Create(ExistingNotificationId);
            var transport    = new TransportRoute(ExistingNotificationId);

            transport.AddTransitStateToNotification(TransitStateFactory.Create(ExistingTransitStateId,
                                                                               CountryFactory.Create(new Guid("3E7A0092-B6CB-46AD-ABCC-FB741EB6CF35")), 1));

            context.NotificationApplications.Add(notification);
            context.TransportRoutes.Add(transport);

            var repository = A.Fake <ITransportRouteRepository>();

            A.CallTo(() => repository.GetByNotificationId(ExistingNotificationId)).Returns(transport);

            handler = new RemoveTransitStateForNotificationHandler(context, repository);
        }
Ejemplo n.º 21
0
        public void MoreThanThreeStatesDisplaysInAnnexTest()
        {
            var statesList = new List <TransitState>();

            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "one"), "short name"));
            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "two"), "short name"));
            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "three"), "short name"));
            statesList.Add(TransitState(CountryFactory.Create(Guid.Empty, "four"), "short name"));

            var vm = new TransitStateViewModel(statesList);

            vm.SetAnnexMessage(6);

            Assert.Equal("See Annex 6", vm.AnnexMessage);
            Assert.Equal(string.Empty, vm.MiddleCountry);
            Assert.Equal(string.Empty, vm.LeftCountry);
            Assert.Equal(string.Empty, vm.RightCountry);
            Assert.Equal(4, vm.TransitStateDetails.Count);
            Assert.Equal("one", vm.TransitStateDetails[0].Country);
            Assert.Equal("two", vm.TransitStateDetails[1].Country);
            Assert.Equal("three", vm.TransitStateDetails[2].Country);
            Assert.Equal("four", vm.TransitStateDetails[3].Country);
        }
        public SetExitCustomsOfficeForNotificationByIdHandlerTests()
        {
            this.context = new TestIwsContext();
            var repository = A.Fake <ITransportRouteRepository>();

            anyNotification = NotificationApplicationFactory.Create(TestIwsContext.UserId, NotificationType.Recovery, UKCompetentAuthority.England, 0);
            EntityHelper.SetEntityId(anyNotification, notificationId);

            transport = new TransportRoute(notificationId);

            context.NotificationApplications.Add(anyNotification);
            context.TransportRoutes.Add(transport);

            country      = CountryFactory.Create(AnyGuid);
            nonEuCountry = CountryFactory.Create(new Guid("606ECF5A-6571-4803-9CCA-7E1AF82D147A"), "test", false);

            context.Countries.AddRange(new[]
            {
                country,
                nonEuCountry
            });

            stateOfExport = new StateOfExport(country,
                                              CompetentAuthorityFactory.Create(AnyGuid, country),
                                              EntryOrExitPointFactory.Create(AnyGuid, country));

            stateOfImportNonEu = new StateOfImport(nonEuCountry,
                                                   CompetentAuthorityFactory.Create(new Guid("5E4F1F22-5054-449B-9EC7-933A43BB5D6D"), nonEuCountry),
                                                   EntryOrExitPointFactory.Create(new Guid("9781324F-17B8-4009-89B2-C18963E3E6E1"), nonEuCountry));

            A.CallTo(() => repository.GetByNotificationId(notificationId)).Returns(transport);

            this.handler   = new SetExitCustomsOfficeForNotificationByIdHandler(context, repository);
            this.validator = A.Fake <ITransportRouteValidator>();
            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(null, stateOfExport)).Returns(true);
            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(stateOfImportNonEu, stateOfExport)).Returns(true);
        }
Ejemplo n.º 23
0
        public void createOracletestRecords()
        {
            ModelContext.Current.config.DoCascadeDeletes = true;
            ModelContext.beginTrans();
            ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(EmployeeValidator));

            try {
                Employee e = EmployeeFactory.Create();
                e.PrDepartment = DepartmentFactory.Create();
                e.PrDepartment.PrDepartmentName = "My New Dept";
                e.PrDepartment.PrLocationId     = LocationDataUtils.findList()[0].PrLocationId;

                e.PrFirstName   = "test";
                e.PrLastName    = "Lastname";
                e.PrSALARY      = 100m;
                e.PrEMAIL       = "*****@*****.**";
                e.PrPhoneNumber = "1030045";
                e.PrHireDate    = new DateTime(DateTime.Now.Year, 1, 1);
                e.PrJobId       = JobDataUtils.findList()[0].PrJobId;

                e.PrTrainingHistoryAdd(EmployeeTrainingHistoryFactory.Create());
                EmployeeTrainingHistory emplProj = e.PrTrainingHistoryGetAt(0);
                emplProj.PrDateFrom = new DateTime(DateTime.Now.Year, 3, 1);
                emplProj.PrDateTo   = new DateTime(DateTime.Now.Year, 6, 1);

                emplProj.PrTrainingCourse           = TrainingCourseFactory.Create();
                emplProj.PrTrainingCourse.PrCODE    = "X1";
                emplProj.PrTrainingCourse.PrDescrEn = "New Course";
                emplProj.PrTrainingCourse.PrDescrGr = "Νέο";
                Assert.IsTrue(e.isNew);
                Assert.IsTrue(e.isDirty);
                Assert.IsTrue(e.NeedsSave);

                // 3 ways to persist to database
                // method 1: use ModelContext.Current().save

                Assert.IsTrue(e.CreateDate == null, "Before save, created date is null");
                Assert.IsTrue(e.UpdateDate == null, "Before save, UpdateDate is not null");
                ModelContext.Current.saveModelObject(e);
                Assert.IsTrue(e.PrPhoneNumber == "12345XX", "12345XX value in PrPhoneNumber is Proof that validator was called");
                Assert.IsTrue(e.CreateDate != null, "Before save, created date is not null");
                Assert.IsTrue(e.UpdateDate != null, "Before save, UpdateDate is not null");
                Assert.IsTrue(e.CreateUser != null, "Before save, CreateUser date is not null");
                Assert.IsTrue(e.UpdateUser != null, "Before save, UpdateUser is not null");
                //Assert.IsTrue(e.UpdateDate.Value.Ticks == e.CreateDate.Value.Ticks, "update date = create date after saving new");
                Assert.IsTrue(e.UpdateUser == e.CreateUser, "update date = create date after saving new");

                long x = e.PrEmployeeId;
                Assert.IsFalse(e.isNew, "After save, model object isNew property must return false");
                Assert.IsFalse(e.isDirty, "After save to db, model object isDirty property must return false");

                e = EmployeeDataUtils.findByKey(x);

                Assert.IsNotNull(e, "New employee not found");

                Assert.IsFalse(e.isNew, "After load from db, model object isNew property returns false");
                Assert.IsFalse(e.isDirty, "After load from db, model object isDirty property returns false");

                Assert.AreEqual(e.PrDepartment.PrDepartmentName, "My New Dept");
                Assert.AreEqual(e.PrSALARY, 100m);
                Assert.AreEqual(e.PrLastName, "Lastname");
                Assert.AreEqual(e.PrPhoneNumber, "12345XX");
                Assert.AreEqual(e.PrHireDate, new DateTime(2015, 1, 1));
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 1);
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course");

                //change some values on child and parent objects
                e.PrTrainingHistoryGetAt(0).PrDateTo = new DateTime(DateTime.Now.Year, 6, 1);
                e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn = "New Course Updated"; // here we are updating parent record of child object of employee!
                Assert.IsTrue(e.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true");
                Assert.IsFalse(e.isDirty, "After changing parent or child obejcts values, e.isDirty must be false since we did not change anything on the Model Object");

                // method 2: call [ModelObject]DataUtils.save
                EmployeeDataUtils.saveEmployee(e);
                //Assert.IsTrue(e.UpdateDate > e.CreateDate, "after update of record, update must be date > create date ");
                // note that above test cannot be sucess since save is happening too fast

                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrPhoneNumber = "XXXXX";
                Assert.IsTrue(e.NeedsSave, "After changing value, e.NeedsSave must be true");
                Assert.IsTrue(e.isDirty, "After changing value e.isDirty must be true");

                // method 3: call [ModelObject]dbMapper.save
                new EmployeeDBMapper().saveEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrPhoneNumber, "XXXXX");
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrTrainingHistoryClear();
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked after call to clear");
                EmployeeDataUtils.saveEmployee(e);

                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked, after reloading from db");

                EmployeeDataUtils.deleteEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.IsNull(e, "New employee must have been deleted!");

                // now let's test string primary key
                Country et = CountryFactory.Create();
                et.PrCountryName = "A Description";
                et.PrCountryId   = "XX";

                Country et1 = CountryFactory.Create();
                et1.PrCountryName = "A Description 1";
                et1.PrCountryId   = "Y7";

                Country et2 = CountryFactory.Create();
                et2.PrCountryName = "A Description 2";
                et2.PrCountryId   = "H8";

                CountryDataUtils.saveCountry(et, et1, et2);

                et2 = CountryDataUtils.findByKey("H8");
                Assert.IsNotNull(et2, "New Country must have been created!");
                et1 = CountryDataUtils.findByKey("Y7");
                Assert.IsNotNull(et1, "New Country must have been created!");
            } finally {
                ModelContext.rollbackTrans();
            }
        }
Ejemplo n.º 24
0
        public void RemoveOnlyNonEUTransitState_RaisesAllTransitStatesInEUEvent()
        {
            var importCountry  = CountryFactory.Create(new Guid("EFFD18F8-32F1-48FE-8513-0FD5E45EF730"));
            var exportCountry  = CountryFactory.Create(new Guid("FA92F4B9-CE86-44D7-8554-23D3B07A5269"));
            var transitCountry = CountryFactory.Create(new Guid("873F6164-3DFE-481E-B372-9BD530304E70"), isEuMember: false);

            var transitState = new TransitState(
                transitCountry,
                new TestableCompetentAuthority()
            {
                Country = transitCountry
            },
                new TestableEntryOrExitPoint()
            {
                Country = transitCountry
            },
                new TestableEntryOrExitPoint()
            {
                Country = transitCountry
            },
                4);

            var transitStateId = new Guid("0BE78BE8-F666-4775-B3DA-7C058BFE4F4D");

            EntityHelper.SetEntityId(transitState, transitStateId);

            var stateOfImport = new StateOfImport(
                importCountry,
                new TestableCompetentAuthority()
            {
                Country = importCountry
            },
                new TestableEntryOrExitPoint()
            {
                Country = importCountry
            });
            var stateOfExport = new StateOfExport(
                exportCountry,
                new TestableCompetentAuthority()
            {
                Country = exportCountry
            },
                new TestableEntryOrExitPoint()
            {
                Country = exportCountry
            });

            var validatorMock = A.Fake <ITransportRouteValidator>();

            A.CallTo(() => validatorMock.IsImportAndExportStatesCombinationValid(stateOfImport, null)).Returns(true);
            A.CallTo(() => validatorMock.IsImportAndExportStatesCombinationValid(stateOfImport, stateOfExport)).Returns(true);

            transportRoute.SetStateOfImportForNotification(
                stateOfImport,
                validatorMock);

            transportRoute.SetStateOfExportForNotification(
                stateOfExport,
                validatorMock);

            transportRoute.AddTransitStateToNotification(transitState);

            transportRoute.SetEntryCustomsOffice(new EntryCustomsOffice("entry", "entry", importCountry));
            transportRoute.SetExitCustomsOffice(new ExitCustomsOffice("exit", "exit", exportCountry));

            transportRoute.RemoveTransitState(transitStateId);
        }
Ejemplo n.º 25
0
 [TestMethod] public void CreateWithNullRegionInfoTest()
 {
     o = CountryFactory.Create(null);
     validateResults();
 }
Ejemplo n.º 26
0
 private async Task Add(UsaCountryInfo countryInfo, UsaCountryModel country)
 {
     Country countryToInsert = CountryFactory.Create(country, AssistanceInfoFactory.Create(countryInfo.AssistanceInfo), CountryInfoFactory.Create(countryInfo));
     await countryRepository.InsertAsync(countryToInsert);
 }
Ejemplo n.º 27
0
        public async Task <ActionResult <DataResponse <CountryExtModel> > > Put([FromBody] CountryModel model, [FromRoute] string ID)
        {
            DataResponse <CountryExtModel> response = new DataResponse <CountryExtModel>();
            CountryExtModel _DTO     = null;
            string          errorMsg = String.Empty;

            try
            {
                if (ModelState.IsValid && model != null)
                {
                    // Custom Validations
                    if (!CountryFactory.ValidateModel(model, ID, out errorMsg))
                    {
                        response.Code        = ResponseCode.FAILED;
                        response.Description = ResponseDescription.FAILED;
                        response.Message     = errorMsg;
                        response.Data        = _DTO;
                        return(BadRequest(response));
                    }

                    // Check Entity Exist
                    if (_unitOfWork.Users.CheckExist(model.Name, model.Code, out errorMsg, ID))
                    {
                        response.Code        = ResponseCode.FAILED;
                        response.Description = ResponseDescription.FAILED;
                        response.Message     = errorMsg;
                        response.Data        = _DTO;
                        return(BadRequest(response));
                    }

                    // Generate entity
                    var _entity = CountryFactory.Create(model);

                    // Create user
                    var _country = await _unitOfWork.Users.UpdateAsync(_entity).ConfigureAwait(false);

                    int done = await _unitOfWork.CompleteAsync().ConfigureAwait(false);

                    if (done > 0)
                    {
                        _DTO = _mapper.Map <CountryExtModel>(_country);

                        response.Code        = ResponseCode.SUCCESS;
                        response.Description = ResponseDescription.SUCCESS;
                        response.Message     = null;
                        response.Data        = _DTO;
                        return(Ok(_DTO));
                    }
                }

                response.Code        = ResponseCode.FAILED;
                response.Description = ResponseDescription.FAILED;
                response.Message     = "Invalid user input";
                response.Data        = _DTO;
                return(BadRequest(response));
            }
            catch (Exception ex)
            {
                Guid _ErrorCode = Guid.NewGuid();
                Log.Error("Fatal Error [{ErrorCode}]: {Message}", _ErrorCode, ex.Message);
                response.Code        = ResponseCode.SYSTEM_ERROR;
                response.Description = ResponseDescription.SYSTEM_ERROR;
                response.Message     = $"System Error: Something went wrong here! Kindly contact the support with this error code [{_ErrorCode}]";
                response.Data        = _DTO;
                return(BadRequest(response));
            }
        }
Ejemplo n.º 28
0
 public CustomsOfficeTests()
 {
     country = CountryFactory.Create(new Guid("C294A7AE-D95D-416D-A8DA-F2148EA5F916"));
 }
Ejemplo n.º 29
0
        public void CreateEntryOffice_NonEuropeanCountry_Throws()
        {
            country = CountryFactory.Create(new Guid("0A5C8F28-1061-4017-A0E1-BCE0CAD5B90A"), "test", false);

            Assert.Throws <InvalidOperationException>(() => new EntryCustomsOffice("name", "address", country));
        }
Ejemplo n.º 30
0
 private Country CreateCountry(Guid id, bool isEuMember)
 {
     return(CountryFactory.Create(id, "test", isEuMember));
 }