Exemplo n.º 1
0
        public void Scenario2()
        {
            var unitStoreMock     = new UnitStoreMock();
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var dateServiceMock   = new DateServiceMock();
            var facade            = new Facade(unitStoreMock, customerStoreMock, tenancyStoreMock, dateServiceMock);

            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "A1",
                Length              = 2,
                Width               = 2,
                Height              = 2,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 20
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "B2",
                Length              = 8,
                Width               = 8,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 80
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Bravo"
            });
            dateServiceMock.CurrentDateTime = new DateTime(2017, 01, 01);
            facade.ReserveUnit("A1", "Alpha");
            facade.ReserveUnit("B2", "Alpha");
            dateServiceMock.CurrentDateTime = new DateTime(2017, 03, 01);
            Assert.Equal(200, facade.CalculateAmountDue("Alpha"));
            facade.Pay("Alpha", 150);
            Assert.Equal(50, facade.CalculateAmountDue("Alpha"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 04, 01);
            Assert.Equal(150, facade.CalculateAmountDue("Alpha"));
            facade.Pay("Alpha", 50);
            Assert.Equal(100, facade.CalculateAmountDue("Alpha"));
            facade.Pay("Alpha", 120.43m);
            Assert.Equal(0, facade.CalculateAmountDue("Alpha"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 05, 01);
            Assert.Equal(100, facade.CalculateAmountDue("Alpha"));
            facade.Pay("Alpha", 100);
            Assert.Equal(0, facade.CalculateAmountDue("Alpha"));
            dateServiceMock.CurrentDateTime = new DateTime(2018, 02, 01);
            Assert.Equal(900, facade.CalculateAmountDue("Alpha"));
            facade.Pay("Alpha", 900);
            Assert.Equal(0, facade.CalculateAmountDue("Alpha"));
        }
Exemplo n.º 2
0
        public void CannotReleaseInvalidReservations()
        {
            var unitStoreMock     = new UnitStoreMock();
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var dateServiceMock   = new DateServiceMock();
            var facade            = new Facade(unitStoreMock, customerStoreMock, tenancyStoreMock, dateServiceMock);

            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber = "A1"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha"
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                facade.ReleaseUnit("A1", "Alpha");
            });
            facade.ReserveUnit("A1", "Alpha");
            facade.ReleaseUnit("A1", "Alpha");
            Assert.Throws <InvalidOperationException>(() =>
            {
                facade.ReleaseUnit("A1", "Alpha");
            });
        }
Exemplo n.º 3
0
        public void RejectsDuplicateCustomers()
        {
            var customerStoreMock = new CustomerStoreMock();
            var facade            = new Facade(new UnitStoreDummy(), customerStoreMock, new TenancyStoreDummy(), new DateServiceDummy());

            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Number"
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                facade.AddNewCustomer(new NewCustomer()
                {
                    CustomerNumber = "Number"
                });
            });
        }
Exemplo n.º 4
0
        public void AddsAndDeletesCustomersCorrectly()
        {
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var facade            = new Facade(new UnitStoreMock(), customerStoreMock, tenancyStoreMock, new DateServiceDummy());

            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha",
                FullName       = "Alpha Name",
                Address        = "Alpha Address"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Bravo",
                FullName       = "Bravo Name",
                Address        = "Bravo Address"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Charlie",
                FullName       = "Charlie Name",
                Address        = "Charlie Address"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Delta",
                FullName       = "Delta Name",
                Address        = "Delta Address"
            });
            facade.DeleteCustomer("Charlie");
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Echo",
                FullName       = "Echo Name",
                Address        = "Echo Address"
            });
            facade.DeleteCustomer("Alpha");
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Foxtrot",
                FullName       = "Foxtrot Name",
                Address        = "Foxtrot Address"
            });
            Assert.Equal(4, customerStoreMock.Customers.Count);
            var delta = facade.GetCustomerDetails("Delta");

            Assert.Equal("Delta Name", delta.FullName);
            Assert.Equal("Delta Address", delta.Address);
            var customerNumbers = customerStoreMock.Customers.Select(c => c.CustomerNumber).ToArray();

            Assert.Contains("Bravo", customerNumbers);
            Assert.Contains("Delta", customerNumbers);
            Assert.Contains("Echo", customerNumbers);
            Assert.Contains("Foxtrot", customerNumbers);
        }
Exemplo n.º 5
0
        public void ValidationChecks()
        {
            var facade = new Facade(new UnitStoreDummy(), new CustomerStoreDummy(), new TenancyStoreDummy(), new DateServiceDummy());

            Assert.Throws <ArgumentException>(() =>
            {
                facade.CommissionNewUnit(new NewUnit());
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.DecommissionUnit(String.Empty);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.AddNewCustomer(new NewCustomer());
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.DeleteCustomer(String.Empty);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.ReserveUnit(String.Empty, String.Empty);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.ReleaseUnit(String.Empty, String.Empty);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.CalculateAmountDue(String.Empty);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.Pay(String.Empty, 0);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                facade.Pay("Alpha", -99);
            });
        }
Exemplo n.º 6
0
        public void NullChecks()
        {
            var facade = new Facade(new UnitStoreDummy(), new CustomerStoreDummy(), new TenancyStoreDummy(), new DateServiceDummy());

            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.CommissionNewUnit(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.DecommissionUnit(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.AddNewCustomer(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.DeleteCustomer(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.ReserveUnit(null, null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.ReleaseUnit(null, null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.CalculateAmountDue(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                facade.Pay(null, 0);
            });
        }
Exemplo n.º 7
0
        public void Scenario1()
        {
            var unitStoreMock     = new UnitStoreMock();
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var dateServiceMock   = new DateServiceMock();
            var facade            = new Facade(unitStoreMock, customerStoreMock, tenancyStoreMock, dateServiceMock);

            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "A1",
                Length              = 5,
                Width               = 5,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 50
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "B2",
                Length              = 10,
                Width               = 5,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 60
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "C3",
                Length              = 10,
                Width               = 10,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 70
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "D4",
                Length              = 4,
                Width               = 4,
                Height              = 4,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 100
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "E5",
                Length              = 6,
                Width               = 6,
                Height              = 6,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 110
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "F6",
                Length              = 8,
                Width               = 8,
                Height              = 8,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 120
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Bravo"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Charlie"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Delta"
            });

            facade.UpdateCustomerDetails(new NewCustomer()
            {
                CustomerNumber = "Delta", FullName = "Delta Delta", Address = "Address"
            });

            Assert.Empty(facade.GetCustomerUnits("Alpha"));
            Assert.Empty(facade.GetCustomerUnits("Bravo"));
            Assert.Empty(facade.GetCustomerUnits("Charlie"));

            var details = facade.GetCustomerDetails("Delta");

            Assert.Equal("Delta", details.CustomerNumber);
            Assert.Equal("Delta Delta", details.FullName);
            Assert.Equal("Address", details.Address);

            var find1 = facade.SearchAvailableUnits(null, null, null).ToArray();

            Assert.Equal(6, find1.Length);
            var find2 = facade.SearchAvailableUnits(true, null, 70).ToArray();

            Assert.Equal(2, find2.Length);
            var find3 = facade.SearchAvailableUnits(null, true, 750).ToArray();

            Assert.Single(find3);
            var unit = find3.Single();

            Assert.Equal("C3", unit.UnitNumber);
            dateServiceMock.CurrentDateTime = new DateTime(2017, 01, 01);
            facade.ReserveUnit("C3", "Charlie");

            var charliesUnits = facade.GetCustomerUnits("Charlie");

            Assert.Single(charliesUnits);
            Assert.True(charliesUnits.Single().UnitNumber == "C3");
            Assert.True(charliesUnits.Single().ReservationDate == new DateTime(2017, 01, 01));
            Assert.True(charliesUnits.Single().AmountPaid == 0);

            dateServiceMock.CurrentDateTime = new DateTime(2017, 03, 01);
            Assert.Equal(140, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 04, 01);
            Assert.Equal(210, facade.CalculateAmountDue("Charlie"));
            facade.Pay("Charlie", 180);
            Assert.Equal(30, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 05, 01);
            Assert.Equal(100, facade.CalculateAmountDue("Charlie"));
            facade.Pay("Charlie", 100);
            Assert.Equal(0, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 06, 01);
            Assert.Equal(70, facade.CalculateAmountDue("Charlie"));
            var find4 = facade.SearchAvailableUnits(null, true, 750).ToArray();

            Assert.Empty(find4);
            facade.Pay("Charlie", 70);
            facade.ReleaseUnit("C3", "Charlie");
            dateServiceMock.CurrentDateTime = new DateTime(2017, 07, 01);
            Assert.Equal(0, facade.CalculateAmountDue("Charlie"));
            var find5 = facade.SearchAvailableUnits(null, true, 750).ToArray();

            Assert.Single(find5);
            var find6 = facade.SearchAvailableUnits(null, null, null).ToArray();

            Assert.Equal(6, find6.Length);
            var customerLookup = facade.ListCustomersAndTenants();

            Assert.Equal(4, customerLookup.Count());
        }
Exemplo n.º 8
0
        public void CantDeleteCustomersWithReservedUnits()
        {
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var unitStoreMock     = new UnitStoreMock();
            var dateServiceMock   = new DateServiceMock();
            var facade            = new Facade(unitStoreMock, customerStoreMock, tenancyStoreMock, dateServiceMock);

            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha",
                FullName       = "Alpha Name",
                Address        = "Alpha Address"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Bravo",
                FullName       = "Bravo Name",
                Address        = "Bravo Address"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Charlie",
                FullName       = "Charlie Name",
                Address        = "Charlie Address"
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "1A",
                Length              = 10,
                Width               = 12,
                Height              = 14,
                IsClimateControlled = true,
                IsVehicleAccessible = true,
                PricePerMonth       = 90
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "2B",
                IsClimateControlled = false,
                IsVehicleAccessible = false,
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "3C",
                IsClimateControlled = true,
                IsVehicleAccessible = false,
            });

            dateServiceMock.CurrentDateTime = new DateTime(2017, 01, 01);

            facade.ReserveUnit("1A", "Alpha");
            facade.ReserveUnit("2B", "Bravo");
            facade.ReserveUnit("3C", "Charlie");

            Assert.Throws <InvalidOperationException>(() => facade.DeleteCustomer("Alpha"));
            facade.ReleaseUnit("1A", "Alpha");
            facade.DeleteCustomer("Alpha");
            Assert.Equal(2, customerStoreMock.Customers.Count());

            Assert.Throws <InvalidOperationException>(() => facade.DeleteCustomer("Bravo"));
            facade.ReleaseUnit("2B", "Bravo");
            facade.DeleteCustomer("Bravo");
            Assert.Single(customerStoreMock.Customers);
        }
        public void Scenario1()
        {
            var unitStoreMock     = new UnitStoreMock();
            var customerStoreMock = new CustomerStoreMock();
            var tenancyStoreMock  = new TenancyStoreMock();
            var dateServiceMock   = new DateServiceMock();
            var facade            = new Facade(unitStoreMock, customerStoreMock, tenancyStoreMock, dateServiceMock);

            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "A1",
                Length              = 5,
                Width               = 5,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 50
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "B2",
                Length              = 10,
                Width               = 5,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 60
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "C3",
                Length              = 10,
                Width               = 10,
                Height              = 8,
                IsClimateControlled = false,
                IsVehicleAccessible = true,
                PricePerMonth       = 70
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "D4",
                Length              = 4,
                Width               = 4,
                Height              = 4,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 100
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "E5",
                Length              = 6,
                Width               = 6,
                Height              = 6,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 110
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "F6",
                Length              = 8,
                Width               = 8,
                Height              = 8,
                IsClimateControlled = true,
                IsVehicleAccessible = false,
                PricePerMonth       = 120
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Alpha"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Bravo"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Charlie"
            });
            facade.AddNewCustomer(new NewCustomer()
            {
                CustomerNumber = "Delta"
            });
            var find1 = facade.FindAvailableUnits(null, null, null).ToArray();

            Assert.Equal(6, find1.Length);
            var find2 = facade.FindAvailableUnits(true, null, 70).ToArray();

            Assert.Equal(2, find2.Length);
            var find3 = facade.FindAvailableUnits(null, true, 750).ToArray();

            Assert.Equal(1, find3.Length);
            var unit = find3.Single();

            Assert.Equal("C3", unit.UnitNumber);
            dateServiceMock.CurrentDateTime = new DateTime(2017, 01, 01);
            facade.ReserveUnit("C3", "Charlie");
            dateServiceMock.CurrentDateTime = new DateTime(2017, 03, 01);
            Assert.Equal(140, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 04, 01);
            Assert.Equal(210, facade.CalculateAmountDue("Charlie"));
            facade.Pay("Charlie", 180);
            Assert.Equal(30, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 05, 01);
            Assert.Equal(100, facade.CalculateAmountDue("Charlie"));
            facade.Pay("Charlie", 100);
            Assert.Equal(0, facade.CalculateAmountDue("Charlie"));
            dateServiceMock.CurrentDateTime = new DateTime(2017, 06, 01);
            Assert.Equal(70, facade.CalculateAmountDue("Charlie"));
            var find4 = facade.FindAvailableUnits(null, true, 750).ToArray();

            Assert.Equal(0, find4.Length);
            facade.Pay("Charlie", 70);
            facade.ReleaseUnit("C3", "Charlie");
            dateServiceMock.CurrentDateTime = new DateTime(2017, 07, 01);
            Assert.Equal(0, facade.CalculateAmountDue("Charlie"));
            var find5 = facade.FindAvailableUnits(null, true, 750).ToArray();

            Assert.Equal(1, find5.Length);
            var find6 = facade.FindAvailableUnits(null, null, null).ToArray();

            Assert.Equal(6, find6.Length);
        }