public void RegistrationController_AddContact_POST_NotManualRegistration_RedirectToConfirmOrganisation()
        {
            //ARRANGE:
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };

            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(RegistrationController.AddContact));
            routeData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user);

            var model = new OrganisationViewModel {
                OrganisationName      = "Acme ltd",
                Address1              = "123",
                Address3              = "WestMinster",
                Postcode              = "W1A 2ED",
                SelectedEmployerIndex = 0,
                SearchText            = "smith",
                ManualRegistration    = false,
                ManualAddress         = true,
                SectorType            = SectorTypes.Public,
                SicCodes              = new List <int>(),
                ManualEmployers       = new List <EmployerRecord>()
            };

            controller.StashModel(model);

            OrganisationViewModel savedModel = model.GetClone();

            savedModel.ContactEmailAddress = "[email protected]";
            savedModel.ContactFirstName    = "test firstName2";
            savedModel.ContactLastName     = "test lastName2";
            savedModel.ContactJobTitle     = "test job title2";
            savedModel.ContactPhoneNumber  = "79004 123 456";
            controller.Bind(savedModel);

            //Set the expected model
            OrganisationViewModel expectedModel = model.GetClone();

            expectedModel.ConfirmReturnAction = nameof(RegistrationController.AddContact);

            //ACT:
            //2.Run and get the result of the test
            var result         = controller.AddContact(model) as RedirectToActionResult;
            var unstashedModel = controller.UnstashModel <OrganisationViewModel>();

            //ASSERT:
            Assert.NotNull(result, "Expected RedirectToActionResult", "Wrong redirect");
            Assert.That(result.ActionName == nameof(RegistrationController.ConfirmOrganisation), "Redirected to the wrong action");
            Assert.NotNull(unstashedModel, "Expected Stashed OrganisationViewModel");

            //Check result is same as expected
            expectedModel.Compare(unstashedModel);
        }
        public void RegistrationController_AddSector_POST_Success()
        {
            //ARRANGE:
            //1.Arrange the test setup variables
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };

            //Set user email address verified code and expired sent date
            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(RegistrationController.AddSector));
            routeData.Values.Add("Controller", "Registration");

            var employerResult = new PagedResult <EmployerRecord>();

            employerResult.Results = new List <EmployerRecord>();

            //use the include and exclude functions here to save typing
            var model = new OrganisationViewModel {
                NoReference           = false,
                OrganisationName      = "Acme ltd",
                NameSource            = "CoHo",
                DUNSNumber            = "012345678",
                CompanyNumber         = "12345678",
                CharityNumber         = "Charity1",
                MutualNumber          = "Mutual1",
                OtherName             = "OtherName1",
                OtherValue            = "OtherValue1",
                DateOfCessation       = VirtualDateTime.Now,
                ManualAddress         = false,
                AddressSource         = "CoHo",
                Address1              = "123",
                Address2              = "evergreen terrace",
                Address3              = "Westminster",
                City                  = "City1",
                County                = "County1",
                Country               = "United Kingdom",
                PoBox                 = "PoBox 12",
                Postcode              = "W1 5qr",
                ContactEmailAddress   = "*****@*****.**",
                ContactFirstName      = "test firstName",
                ContactLastName       = "test lastName",
                ContactJobTitle       = "test job title",
                ContactPhoneNumber    = "79000 000 000",
                SicCodeIds            = "1,2,3,4",
                SicSource             = "CoHo",
                SearchText            = "Searchtext",
                ManualRegistration    = false,
                SectorType            = SectorTypes.Private,
                PINExpired            = false,
                PINSent               = false,
                SelectedEmployerIndex = 0,
                Employers             = employerResult, //0 record returned
                ManualEmployers       = new List <EmployerRecord>(),
                ManualEmployerIndex   = -1,
                AddressReturnAction   = nameof(RegistrationController.ConfirmOrganisation),
                ConfirmReturnAction   = nameof(RegistrationController.ChooseOrganisation)
            };

            var sic1 = new SicCode {
                SicCodeId = 1420, SicSectionId = "SSID1", SicSection = new SicSection {
                    SicSectionId = "5221"
                }, Description = ""
            };
            var sic2 = new SicCode {
                SicCodeId = 14310, SicSectionId = "SSID1", SicSection = new SicSection {
                    SicSectionId = "4115"
                }, Description = ""
            };

            var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user, sic1, sic2);

            //Stash the object for the unstash to happen in code
            controller.StashModel(model);

            OrganisationViewModel savedModel = model.GetClone();

            savedModel.SicCodeIds = "1420,14310";
            controller.Bind(savedModel);
            OrganisationViewModel expectedModel = savedModel.GetClone();

            expectedModel.SicSource           = user.EmailAddress;
            expectedModel.ConfirmReturnAction = nameof(RegistrationController.AddSector);

            //ACT:
            //2.Run and get the result of the test
            var result = controller.AddSector(savedModel) as RedirectToActionResult;

            //ASSERTS:
            //3.Check that the result is not null
            Assert.NotNull(result, "Expected RedirectToActionResult");

            //4.Check that the redirection went to the right url step.
            Assert.That(result.ActionName == nameof(RegistrationController.ConfirmOrganisation), "Redirected to the wrong view");

            //5.If the redirection successfull retrieve the model stash sent with the redirect.
            var unstashedModel = controller.UnstashModel <OrganisationViewModel>();

            //6.Check that the unstashed model is not null
            Assert.NotNull(unstashedModel, "Expected OrganisationViewModel");

            //Check result is same as expected
            expectedModel.Compare(unstashedModel);
        }
        public void RegistrationController_AddAddress_POST_AuthorisedNoAddress_ToConfirm()
        {
            //ARRANGE:
            //1.Arrange the test setup variables
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };

            var address0 = new OrganisationAddress {
                AddressId = 1,
                Status    = AddressStatuses.Active,
                Source    = "CoHo",
                Address1  = "123",
                Address2  = "evergreen terrace",
                Address3  = "Westminster",
                TownCity  = "City1",
                County    = "County1",
                Country   = "United Kingdom",
                PoBox     = "PoBox 12",
                PostCode  = "W1 5qr"
            };

            var sicCode1 = new SicCode {
                SicCodeId = 2100, Description = "Desc1", SicSection = new SicSection {
                    SicSectionId = "4321", Description = "Section1"
                }
            };
            var sicCode2 = new SicCode {
                SicCodeId = 10520, Description = "Desc2", SicSection = new SicSection {
                    SicSectionId = "4326", Description = "Section2"
                }
            };
            var org0 = new Core.Entities.Organisation {
                OrganisationId   = 1,
                OrganisationName = "Company1",
                SectorType       = SectorTypes.Private,
                Status           = OrganisationStatuses.Active,
                CompanyNumber    = "12345678"
            };

            org0.OrganisationAddresses.Add(address0);
            var name = new OrganisationName {
                OrganisationNameId = 1,
                Name           = org0.OrganisationName,
                Created        = org0.Created,
                Organisation   = org0,
                OrganisationId = org0.OrganisationId
            };

            org0.OrganisationNames.Add(name);
            var sic1 = new OrganisationSicCode {
                SicCode        = sicCode1,
                SicCodeId      = 2100,
                Created        = org0.Created,
                Organisation   = org0,
                OrganisationId = org0.OrganisationId
            };

            org0.OrganisationSicCodes.Add(sic1);
            var sic2 = new OrganisationSicCode {
                SicCode        = sicCode2,
                SicCodeId      = 10520,
                Created        = org0.Created,
                Organisation   = org0,
                OrganisationId = org0.OrganisationId
            };

            org0.OrganisationSicCodes.Add(sic2);

            //Set user email address verified code and expired sent date
            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(RegistrationController.AddAddress));
            routeData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <RegistrationController>(user.UserId, routeData, user, org0, address0, name, sic1, sic2);

            var employerResult = new PagedResult <EmployerRecord>();

            employerResult.Results = new List <EmployerRecord> {
                EmployerRecord.Create(org0)
            };

            //use the include and exclude functions here to save typing
            var model = new OrganisationViewModel {
                NoReference           = false,
                SearchText            = "Searchtext",
                ManualAddress         = true,
                SelectedAuthorised    = true,
                ManualRegistration    = false,
                SectorType            = SectorTypes.Public,
                PINExpired            = false,
                PINSent               = false,
                SelectedEmployerIndex = 0,
                Employers             = employerResult, //0 record returned
                ManualEmployers       = new List <EmployerRecord>(),
                ManualEmployerIndex   = -1,
                AddressReturnAction   = nameof(RegistrationController.ConfirmOrganisation),
                ConfirmReturnAction   = nameof(RegistrationController.ChooseOrganisation)
            };


            //Stash the object for the unstash to happen in code
            controller.StashModel(model);

            OrganisationViewModel savedModel = model.GetClone();

            savedModel.Address1 = "Unit 2";
            savedModel.Address2 = "Bank Road";
            savedModel.Address3 = "Essex";
            savedModel.Postcode = "PoStCode 13";
            controller.Bind(savedModel);

            //Set the expected model
            OrganisationViewModel expectedModel = savedModel.GetClone();

            expectedModel.AddressSource       = user.EmailAddress;
            expectedModel.ConfirmReturnAction = nameof(RegistrationController.AddAddress);

            //ACT:
            var result = controller.AddAddress(savedModel) as RedirectToActionResult;

            //ASSERTS:
            //3.Check that the result is not null
            Assert.NotNull(result, "Expected RedirectToActionResult");

            //4.Check that the redirection went to the right url step.
            Assert.That(result.ActionName == nameof(RegistrationController.ConfirmOrganisation), "Redirected to the wrong view");

            //5.If the redirection successfull retrieve the model stash sent with the redirect.
            var unstashedModel = controller.UnstashModel <OrganisationViewModel>();

            //6.Check that the unstashed model is not null
            Assert.NotNull(unstashedModel, "Expected OrganisationViewModel");

            //Check model is same as expected
            expectedModel.Compare(unstashedModel);
        }