示例#1
0
        public void Customer_RentedSingleMovie_Shouldpass()
        {
            const string name = "Nemo";

            var customerNemo = new Customer(name);
            var mrNobody     = new RentalBuilder().Build(new PriceRegular(), "Mr.Nobody", 1);

            customerNemo.Rentals.Add(mrNobody);

            var statement = new Statement(customerNemo);

            var movieDict = new Dictionary <string, double>();

            movieDict["Mr.Nobody"] = 2;
            const int total           = 2;
            const int frequency       = 1;
            var       stringStatement = StringStatement.Create(statement);
            var       jsonStatement   = JsonStatement.Create(statement);

            Assert.IsTrue(CheckStatement(statement, movieDict, name, total, frequency));
            Assert.IsTrue(CheckStandartStringStatement(stringStatement, movieDict, name, total, frequency));
            Assert.IsTrue(CheckJson(jsonStatement, movieDict, name, total, frequency));

            Assert.IsTrue(CheckComposite(Composite.Create(statement), stringStatement, jsonStatement));
        }
示例#2
0
        public void Customer_RentedMultipleMovies_Shouldpass()
        {
            const string name = "Nemo";

            var customerNemo = new Customer(name);
            var mrNobody     = new RentalBuilder().Build(new PriceRegular(), "Mr.Nobody", 5);

            mrNobody.DaysRented = 5;
            customerNemo.Rentals.Add(mrNobody);

            var movie2 = new RentalBuilder().Build(new PriceNewRelease(), "Another movie for Nemo", 10);

            movie2.DaysRented = 10;
            customerNemo.Rentals.Add(movie2);

            var movie3 = new RentalBuilder().Build(new PriceChildren(), "Third Movie for Nemo", 23);

            movie3.DaysRented = 23;
            customerNemo.Rentals.Add(movie3);

            var statement = new Statement(customerNemo);

            var movieDict = new Dictionary <string, double>();

            movieDict["Mr.Nobody"] = 6.5;
            movieDict["Another movie for Nemo"] = 30;
            movieDict["Third Movie for Nemo"]   = 31.5;
            const int total     = 68;
            const int frequency = 4;

            Assert.IsTrue(CheckStatement(statement, movieDict, name, total, frequency));
            Assert.IsTrue(CheckStandartStringStatement(new StringStatement(statement).Result, movieDict, name, total, frequency));
            Assert.IsTrue(CheckJson(new JsonStatement(statement).Result, movieDict, name, total, frequency));
        }
示例#3
0
        public void ManyCustomers_RentedMultipleMovies_Shouldpass()
        {
            const string name  = "Nemo";
            const string name2 = "Neo";

            var customerNemo = new Customer(name);
            var customerNeo  = new Customer(name2);

            var mrNobody = new RentalBuilder().Build(new PriceRegular(), "Mr.Nobody", 1);

            mrNobody.DaysRented = 1;

            var movie2 = new RentalBuilder().Build(new PriceNewRelease(), "Another movie for Nemo", 1);

            movie2.DaysRented = 1;

            var matrix = new RentalBuilder().Build(new PriceChildren(), "The Matrix", 1);

            matrix.DaysRented = 1;

            customerNemo.Rentals.Add(mrNobody);
            customerNemo.Rentals.Add(movie2);

            customerNeo.Rentals.Add(matrix);
            customerNeo.Rentals.Add(movie2);

            var statementNemo = new Statement(customerNemo);

            var movieDict = new Dictionary <string, double>();

            movieDict["Mr.Nobody"] = 2;
            movieDict["Another movie for Nemo"] = 3;
            const int total     = 5;
            const int frequency = 2;

            Assert.IsTrue(CheckStatement(statementNemo, movieDict, name, total, frequency));
            Assert.IsTrue(CheckStandartStringStatement(new StringStatement(statementNemo).Result, movieDict, name, total, frequency));
            Assert.IsTrue(CheckJson(new JsonStatement(statementNemo).Result, movieDict, name, total, frequency));

            var statementNeo = new Statement(customerNeo);

            var movieDictNeo = new Dictionary <string, double>();

            movieDictNeo["The Matrix"]             = 1.5;
            movieDictNeo["Another movie for Nemo"] = 3;
            const double totalNeo     = 4.5;
            const int    frequencyNeo = 2;

            // нужно "схлопнуть код", как сказал по поводу моего кода Андрей, чтобы избежать дублирования,
            //так как куски абсолютно аналогичные (:
            Assert.IsTrue(CheckStatement(statementNeo, movieDictNeo, name2, totalNeo, frequencyNeo));
            Assert.IsTrue(CheckStandartStringStatement(new StringStatement(statementNeo).Result, movieDictNeo, name2, totalNeo, frequencyNeo));
            Assert.IsTrue(CheckJson(new JsonStatement(statementNeo).Result, movieDictNeo, name2, totalNeo, frequencyNeo));
        }
示例#4
0
        public void ManyCustomers_RentedMultipleMovies_Shouldpass()
        {
            const string name  = "Nemo";
            const string name2 = "Neo";

            var customerNemo = new Customer(name);
            var customerNeo  = new Customer(name2);

            var mrNobody = new RentalBuilder().Build(new PriceRegular(), "Mr.Nobody", 1);

            mrNobody.DaysRented = 1;

            var movie2 = new RentalBuilder().Build(new PriceNewRelease(), "Another movie for Nemo", 1);

            movie2.DaysRented = 1;

            var matrix = new RentalBuilder().Build(new PriceChildren(), "The Matrix", 1);

            matrix.DaysRented = 1;

            customerNemo.Rentals.Add(mrNobody);
            customerNemo.Rentals.Add(movie2);

            customerNeo.Rentals.Add(matrix);
            customerNeo.Rentals.Add(movie2);

            var statementNemo = new Statement(customerNemo);

            var movieDict = new Dictionary <string, double>();

            movieDict["Mr.Nobody"] = 2;
            movieDict["Another movie for Nemo"] = 3;
            const int total     = 5;
            const int frequency = 2;

            Assert.IsTrue(CheckStatement(statementNemo, movieDict, name, total, frequency));
            Assert.IsTrue(CheckStandartStringStatement(new StringStatement(statementNemo).Result, movieDict, name, total, frequency));
            Assert.IsTrue(CheckJson(new JsonStatement(statementNemo).Result, movieDict, name, total, frequency));

            var statementNeo = new Statement(customerNeo);

            var movieDictNeo = new Dictionary <string, double>();

            movieDictNeo["The Matrix"]             = 1.5;
            movieDictNeo["Another movie for Nemo"] = 3;
            const double totalNeo     = 4.5;
            const int    frequencyNeo = 2;

            Assert.IsTrue(CheckStatement(statementNeo, movieDictNeo, name2, totalNeo, frequencyNeo));
            Assert.IsTrue(CheckStandartStringStatement(new StringStatement(statementNeo).Result, movieDictNeo, name2, totalNeo, frequencyNeo));
            Assert.IsTrue(CheckJson(new JsonStatement(statementNeo).Result, movieDictNeo, name2, totalNeo, frequencyNeo));
        }
示例#5
0
        public void Statement_Rental_for_only_two_days_total_amount_should_be_movieprice()
        {
            const decimal movieprice = 2.0m;
            var           rental     = new RentalBuilder().HasPrice(movieprice).IsRentedFor(2).Build();
            var           customer   = new Customer(null);

            customer.AddRental(rental);

            // Act
            var outcome = customer.Statement();

            outcome.Should().Contain($"Amount owed is {movieprice}");
        }
示例#6
0
        public void Statement_Rental_for_more_than_two_days_total_amount_should_have_surcharge()
        {
            const decimal movieprice    = 2.0m;
            const decimal expectedPrice = 5.0m;
            var           rental        = new RentalBuilder().HasPrice(movieprice).IsRentedFor(4).Build();
            var           customer      = new Customer(null);

            customer.AddRental(rental);

            // Act
            var outcome = customer.Statement();

            outcome.Should().Contain($"Amount owed is {expectedPrice}", "Price calculation should be: 2 + ((4 - 2) * 1.5)");
        }
示例#7
0
        public void Statement_Rented_movie_should_be_listed_once()
        {
            // Arrange
            const string expectedTitle = "Matrix";
            var          rental        = new RentalBuilder().WithTitle(expectedTitle).Build();
            var          customer      = new Customer(null);

            customer.AddRental(rental);

            // Act
            var outcome = customer.Statement();

            // Assert
            outcome.Should().Contain(expectedTitle, Exactly.Once());
        }