Пример #1
0
        public void AddUserReview_CorrectInput_AllCorrectCalls()
        {
            var result = uut.AddUserReview(defaultReviewDto);

            // Nsubstitute assertions
            mockUnitOfWork.ReviewRepository.Received(1).Add(Arg.Any <Review>());
            mockUnitOfWork.Received(1).UpdateBarRating(defaultReviewDto.BarName);
            mockUnitOfWork.Received(2).Complete();
        }
Пример #2
0
        public void ReviewAddedFromSameUserTwice_ReturnsBadRequest_ReviewNotChanged()
        {
            var barController = new BarController(_uow, _mapper);

            barController.AddBar(new BarDto()
            {
                BarName          = "Bar1",
                AvgRating        = 0.0,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 1235,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });

            var customerController = new CustomerController(_uow, _mapper);

            customerController.AddCustomer(new CustomerDto
            {
                DateOfBirth   = DateTime.Now,
                Email         = "*****@*****.**",
                FavoriteBar   = "Bar1",
                FavoriteDrink = "Øl",
                Name          = "TestKunde",
                Username      = "******",
            });

            var reviewController = new ReviewController(_uow, _mapper);

            reviewController.AddUserReview(new ReviewDto()
            {
                BarName     = "Bar1",     // Bar added
                Username    = "******", // User added
                BarPressure = 5,          // Rating
            });                           // Add review
            var result = reviewController.AddUserReview(new ReviewDto()
            {
                BarName     = "Bar1",
                Username    = "******",
                BarPressure = 1,
            });    // Add another from same user

            var secondBarController = CreateBarController();
            var bar = (secondBarController.GetBar("Bar1") as OkObjectResult).Value as BarDto;

            Assert.That(result, Is.TypeOf <BadRequestResult>());
            Assert.That(bar.AvgRating, Is.EqualTo(5)); // Check rating has not changed.
        }
Пример #3
0
        public void ChangeUserReview_AvgRatingChangedForBar()
        {
            var barController = new BarController(_uow, _mapper);

            barController.AddBar(new BarDto()
            {
                BarName          = "Bar1",
                AvgRating        = 0.0,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 1235,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });

            var customerController = new CustomerController(_uow, _mapper);

            customerController.AddCustomer(new CustomerDto
            {
                DateOfBirth   = DateTime.Now,
                Email         = "*****@*****.**",
                FavoriteBar   = "Bar1",
                FavoriteDrink = "Øl",
                Name          = "TestKunde",
                Username      = "******",
            });

            var reviewController = new ReviewController(_uow, _mapper);

            reviewController.AddUserReview(new ReviewDto()
            {
                BarName     = "Bar1",     // Bar added
                Username    = "******", // User added
                BarPressure = 5,          // Rating
            });                           // Add review
            reviewController.EditUserReview(new ReviewDto()
            {
                BarName     = "Bar1",
                Username    = "******",
                BarPressure = 1,
            }); // Edit it at a later time.

            var secondBarController = CreateBarController();
            var resultObj           = (secondBarController.GetBar("Bar1") as OkObjectResult).Value as BarDto;

            Assert.That(resultObj.AvgRating, Is.EqualTo(1));
        }
Пример #4
0
        public void AddReview_BarHasUpdatedRating_ReviewIsSaved()
        {
            var barController = new BarController(_uow, _mapper);

            barController.AddBar(new BarDto()
            {
                BarName          = "Bar1",
                AvgRating        = 0.0,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 1235,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });

            var customerController = new CustomerController(_uow, _mapper);

            customerController.AddCustomer(new CustomerDto
            {
                DateOfBirth   = DateTime.Now,
                Email         = "*****@*****.**",
                FavoriteBar   = "Bar1",
                FavoriteDrink = "Øl",
                Name          = "TestKunde",
                Username      = "******",
            });

            var reviewController = new ReviewController(_uow, _mapper);
            var reviewResult     = reviewController.AddUserReview(new ReviewDto()
            {
                BarName     = "Bar1",     // Bar added
                Username    = "******", // User added
                BarPressure = 5,          // Rating
            });

            var secondBarController = CreateBarController();

            var barResult = (secondBarController.GetBar("Bar1") as OkObjectResult)
                            .Value as BarDto;

            Assert.That(reviewResult, Is.TypeOf <CreatedResult>());
            Assert.That(barResult.AvgRating, Is.EqualTo(5));
        }