public async Task UpdateOrganisationDetailsHandler_WithValidData_FetchesOrganisationAndUpdatesAndSaves()
        {
            // Arrange
            OrganisationData organisationData = new OrganisationData();
            organisationData.Id = new Guid("9a310218-311b-460d-bd50-9d246c237dcc");
            organisationData.OrganisationType = OrganisationType.RegisteredCompany;
            organisationData.Name = "CompanyName";
            organisationData.CompanyRegistrationNumber = "123456789";
            organisationData.OrganisationName = "CompanyName";
            organisationData.BusinessAddress = new Core.Shared.AddressData();
            organisationData.BusinessAddress.Address1 = "Address1";
            organisationData.BusinessAddress.Address2 = "Address2";
            organisationData.BusinessAddress.TownOrCity = "Town";
            organisationData.BusinessAddress.CountyOrRegion = "County";
            organisationData.BusinessAddress.Postcode = "Postcode";
            organisationData.BusinessAddress.CountryId = new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4");
            organisationData.BusinessAddress.Telephone = "012345678";
            organisationData.BusinessAddress.Email = "*****@*****.**";

            UpdateOrganisationDetails request = new UpdateOrganisationDetails(organisationData);

            IOrganisationDetailsDataAccess dataAccess = A.Fake<IOrganisationDetailsDataAccess>();
            IWeeeAuthorization weeeAuthorization = A.Fake<IWeeeAuthorization>();

            Organisation organisation = A.Dummy<Organisation>();
            A.CallTo(() => dataAccess.FetchOrganisationAsync(new Guid("9a310218-311b-460d-bd50-9d246c237dcc")))
                .Returns(organisation);

            Country country = new Country(
                new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4"),
                "Name");
            A.CallTo(() => dataAccess.FetchCountryAsync(new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4")))
                .Returns(country);

            UpdateOrganisationDetailsHandler handler = new UpdateOrganisationDetailsHandler(dataAccess, weeeAuthorization);

            // Act
            bool result = await handler.HandleAsync(request);

            // Assert
            A.CallTo(() => dataAccess.FetchOrganisationAsync(new Guid("9a310218-311b-460d-bd50-9d246c237dcc")))
                .MustHaveHappened(Repeated.Exactly.Once);

            Assert.Equal("CompanyName", organisation.Name);
            Assert.Equal("123456789", organisation.CompanyRegistrationNumber);
            Assert.Equal("Address1", organisation.BusinessAddress.Address1);
            Assert.Equal("Address2", organisation.BusinessAddress.Address2);
            Assert.Equal("Town", organisation.BusinessAddress.TownOrCity);
            Assert.Equal("County", organisation.BusinessAddress.CountyOrRegion);
            Assert.Equal("Postcode", organisation.BusinessAddress.Postcode);
            Assert.Equal(new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4"), organisation.BusinessAddress.Country.Id);
            Assert.Equal("012345678", organisation.BusinessAddress.Telephone);
            Assert.Equal("*****@*****.**", organisation.BusinessAddress.Email);

            A.CallTo(() => dataAccess.SaveAsync())
                .MustHaveHappened(Repeated.Exactly.Once);

            Assert.Equal(result, true);
        }
        public async Task UpdateDetails_Address_Changes_Address()
        {
            var prefix  = "updated";
            var request = new UpdateOrganisationDetails(new OrganisationRegistrationData()
            {
                OrganisationId = organisationId,
                Name           = prefix + name,
                BusinessType   = Core.Shared.BusinessType.SoleTrader,
                Address        = new AddressData {
                    Address2 = address2, StreetOrSuburb = address1, CountryId = countryId, PostalCode = postcode, TownOrCity = town
                }
            });
            var orgId = await handler.HandleAsync(request);

            var user = await context.Users.SingleAsync(x => x.Id == userId.ToString());

            Assert.Equal(address1, user.Address.Address.Address1);
        }
        public async Task UpdateOrganisationDetailsHandler_WithValidData_FetchesOrganisationAndUpdatesAndSaves()
        {
            // Arrange
            var organisationData = new OrganisationData
            {
                Id = new Guid("9a310218-311b-460d-bd50-9d246c237dcc"),
                OrganisationType          = OrganisationType.RegisteredCompany,
                Name                      = "CompanyName",
                CompanyRegistrationNumber = "123456789",
                OrganisationName          = "CompanyName",
                BusinessAddress           = new Core.Shared.AddressData
                {
                    Address1       = "Address1",
                    Address2       = "Address2",
                    TownOrCity     = "Town",
                    CountyOrRegion = "County",
                    Postcode       = "Postcode",
                    CountryId      = new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4"),
                    Telephone      = "012345678",
                    Email          = "*****@*****.**"
                }
            };

            var request = new UpdateOrganisationDetails(organisationData);

            var dataAccess        = A.Fake <IOrganisationDetailsDataAccess>();
            var weeeAuthorization = A.Fake <IWeeeAuthorization>();

            var organisation = A.Dummy <Organisation>();

            A.CallTo(() => dataAccess.FetchOrganisationAsync(new Guid("9a310218-311b-460d-bd50-9d246c237dcc")))
            .Returns(organisation);

            var country = new Country(
                new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4"),
                "Name");

            A.CallTo(() => dataAccess.FetchCountryAsync(new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4")))
            .Returns(country);

            var handler = new UpdateOrganisationDetailsHandler(dataAccess, weeeAuthorization);

            // Act
            var result = await handler.HandleAsync(request);

            // Assert
            A.CallTo(() => dataAccess.FetchOrganisationAsync(new Guid("9a310218-311b-460d-bd50-9d246c237dcc")))
            .MustHaveHappened(Repeated.Exactly.Once);

            Assert.Equal("CompanyName", organisation.Name);
            Assert.Equal("123456789", organisation.CompanyRegistrationNumber);
            Assert.Equal("Address1", organisation.BusinessAddress.Address1);
            Assert.Equal("Address2", organisation.BusinessAddress.Address2);
            Assert.Equal("Town", organisation.BusinessAddress.TownOrCity);
            Assert.Equal("County", organisation.BusinessAddress.CountyOrRegion);
            Assert.Equal("Postcode", organisation.BusinessAddress.Postcode);
            Assert.Equal(new Guid("79b70dfb-bbfd-4801-9849-880f66ee48e4"), organisation.BusinessAddress.Country.Id);
            Assert.Equal("012345678", organisation.BusinessAddress.Telephone);
            Assert.Equal("*****@*****.**", organisation.BusinessAddress.Email);

            A.CallTo(() => dataAccess.SaveAsync())
            .MustHaveHappened(Repeated.Exactly.Once);

            Assert.Equal(result, true);
        }
        public async Task UpdateDetails_Address_Changes_Address()
        {
            var prefix = "updated";
            var request = new UpdateOrganisationDetails(new OrganisationRegistrationData()
            {
                OrganisationId = organisationId,
                Name = prefix + name,
                BusinessType = Core.Shared.BusinessType.SoleTrader,
                Address = new AddressData { Address2 = address2, StreetOrSuburb = address1, CountryId = countryId, PostalCode = postcode, TownOrCity = town }
            });
            var orgId = await handler.HandleAsync(request);

            var user = await context.Users.SingleAsync(x => x.Id == userId.ToString());
            Assert.Equal(address1, user.Address.Address.Address1);
        }