public void CreateCountry_DifferentCountryCodes_ReturnsDifferentObjects()
 {
     var countryFactory = new CountryFactory(CreateMockValidator());
     var c1 = countryFactory.CreateCountry("BG");
     var c2 = countryFactory.CreateCountry("GB");
     Assert.AreNotSame(c1, c2);
 }
 public void CreateCountry_SameCountryCodes_ReturnsSameObjects()
 {
     var countryFactory = new CountryFactory(CreateMockValidator());
     var c1 = countryFactory.CreateCountry("BG");
     var c2 = countryFactory.CreateCountry("BG");
     Assert.AreSame(c1, c2);
 }
        public void CreateCountry_ValidCountryCode_ReturnsValidObject()
        {
            const string countryCode = "PL";

            var countryFactory = new CountryFactory(CreateMockValidator());
            var country = countryFactory.CreateCountry(countryCode);

            Assert.IsNotNull(country);
            Assert.AreEqual("PL", country.Code);
        }
 public void TwoCountryObjectsShouldShareTheString()
 {
     var country = new string(new char[] { 'D', 'Z' });
     var countryCopy = new string(new char[] { 'D', 'Z' });
     Assert.AreNotSame(country, countryCopy);
     
     var countryFactory = new CountryFactory(CreateMockValidator());
     var c1 = countryFactory.CreateCountry(country);
     var c2 = countryFactory.CreateCountry(countryCopy);
     
     Assert.AreSame(c1, c2);
     Assert.AreSame(c1.Code, c2.Code);
     Assert.AreEqual(c1.Code, country.ToUpperInvariant());
 }
Example #5
0
        public OrderIncomeAggTest()
        {
            OrderIncome order     = new OrderIncome(); //Constructor EF
            string      lastName  = "El rojo";
            string      firstName = "Jhon";
            string      telephone = "+34111111";
            string      company   = "company name";

            _country = CountryFactory.CreateCountry("Spain", "es-ES");

            _customer = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, "*****@*****.**", _country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            for (int i = 0; i < 5; i++)
            {
                Product prod = ProductFactory.CreateProduct("product" + i, "description" + i);
                _products.Add(prod);
            }
        }
        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);
        }
Example #7
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 void LoadCountries()
        {
            ICountry italy    = CountryFactory.CreateItaly();
            ICountry france   = CountryFactory.CreateFrance();
            ICountry bulgaria = CountryFactory.CreateBulgaria();
            ICountry serbia   = CountryFactory.CreateSerbia();
            ICountry germany  = CountryFactory.CreateGermany();
            ICountry brazil   = CountryFactory.CreateBrazil();

            countries.Add(italy);
            countries.Add(france);
            countries.Add(bulgaria);
            countries.Add(serbia);
            countries.Add(germany);
            countries.Add(brazil);

            CountriesDB.Countries = countries;

            ConvertInNewCountry();
        }
        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();
        }
Example #10
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);
        }
Example #11
0
        private void OnSave()
        {
            if (currCountry.CountryName != "" &&
                currCountry.CapitalName != "" &&
                currCountry.CountryInfo != "" &&
                currCountry.CountryPath != "")
            {
                ICountry country = CountryFactory.CreateEmptyCountry();

                country.CountryName = currCountry.CountryName;
                country.CapitalName = currCountry.CapitalName;
                country.CountryInfo = currCountry.CountryInfo;
                country.CountryPath = currCountry.CountryPath;

                CountriesDB.Countries.Add(country);
                //Countries.Add(country);

                currCountry = HelperFunction.ResetCountry(currCountry);

                MessageBox.Show($"Country added successfully!");
            }
        }
Example #12
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);
        }
Example #14
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();
            }
        }
 public void WithBritishZipCode_ReturnsFalseIfFormatsSameLengthButDifferentFormat()
 {
     var cFactory = new CountryFactory(new IsoCountryCodeValidator());
     var pcFactory = new PostalCodeFactory();
     var country = cFactory.CreateCountry("GB");
     var right = new PostalCodeRange(pcFactory.CreatePostalCode(country, "A99 9AA"), pcFactory.CreatePostalCode(country, "B99 9AA"));
     var left = new PostalCodeRange(pcFactory.CreatePostalCode(country, "AA9 9AA"), pcFactory.CreatePostalCode(country, "CC9 9AA"));
     Assert.IsFalse(PostalCodeRange.Contains(left, right));
 }
 [TestMethod] public void CreateValidFromGreaterThanValidToTest()
 {
     o = CountryFactory.Create(id, name, code, validTo, validFrom);
     validateResults(id, name, code, validFrom, validTo);
 }
 public void WithBritishZipCode_ReturnsTrueIfFormatMatchedAndCodesAreContained()
 {
     var cFactory = new CountryFactory(new IsoCountryCodeValidator());
     var pcFactory = new PostalCodeFactory();
     var country = cFactory.CreateCountry("GB");
     var right = new PostalCodeRange(pcFactory.CreatePostalCode(country, "AA9 9AA"), pcFactory.CreatePostalCode(country, "BB9 9AA"));
     var left = new PostalCodeRange(pcFactory.CreatePostalCode(country, "AA9 9AA"), pcFactory.CreatePostalCode(country, "CC9 9AA"));
     Assert.IsTrue(PostalCodeRange.Contains(left, right));
 }
 [TestMethod] public void CreateWithCodeOnlyTest()
 {
     o = CountryFactory.Create(null, null, code);
     validateResults(code, code, code);
 }
 [TestMethod] public void CreateWithNullArgumentsTest()
 {
     o = CountryFactory.Create(null, null, null);
     validateResults();
 }
 [TestMethod] public void CreateWithNullRegionInfoTest()
 {
     o = CountryFactory.Create(null);
     validateResults();
 }
 [TestMethod] public void CreateWithNameOnlyTest()
 {
     o = CountryFactory.Create(null, name, null);
     validateResults(name, name);
 }
Example #22
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);
        }
Example #23
0
 private Country CreateCountry(Guid id, bool isEuMember)
 {
     return(CountryFactory.Create(id, "test", isEuMember));
 }
Example #24
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));
        }
Example #25
0
 public CustomsOfficeTests()
 {
     country = CountryFactory.Create(new Guid("C294A7AE-D95D-416D-A8DA-F2148EA5F916"));
 }
Example #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);
 }
Example #27
0
 public Supermarket()
 {
     menu = CountryFactory.Instance().Menu;
 }
Example #28
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));
            }
        }