示例#1
0
        public void GetBestBars_ReturnedDescendingOrder()
        {
            var barController = new BarController(_uow, _mapper);

            barController.AddBar(new BarDto()
            {
                BarName          = "Bar1",
                AvgRating        = 4.6,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 1235,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });
            barController.AddBar(new BarDto()
            {
                BarName          = "Highest Rated Bar",
                AvgRating        = 5.0,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 12353,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });
            barController.AddBar(new BarDto()
            {
                BarName          = "Bar2",
                AvgRating        = 3.4,
                ShortDescription = "SD",
                AgeLimit         = 18,
                CVR             = 123599,
                Image           = "png.jpg",
                LongDescription = "short",
                Address         = "123 street",
                Email           = "*****@*****.**",
                Educations      = "IKT",
                PhoneNumber     = 0000,
            });

            var secondBarController = CreateBarController();

            var result     = secondBarController.GetBestBars();
            var resultList = (result as OkObjectResult).Value as List <BarSimpleDto>;

            Assert.That(resultList.Count, Is.EqualTo(3));
            Assert.That(resultList[0].BarName, Is.EqualTo("Highest Rated Bar"));
            Assert.That(resultList[0].AvgRating, Is.GreaterThanOrEqualTo(resultList[1].AvgRating));
            Assert.That(resultList[1].AvgRating, Is.GreaterThanOrEqualTo(resultList[2].AvgRating));
        }
示例#2
0
        public void AddBar_SuppliedValidBar_ReturnsCreated()
        {
            // Arrange
            var receivedBarDto = mapper.Map <BarDto>(defaultBar);
            // Act
            var result = uut.AddBar(receivedBarDto);

            // Assert
            mockUnitOfWork.BarRepository.Received(1).Add(Arg.Any <Bar>());
            mockUnitOfWork.Received(1).Complete();
            Assert.That(receivedBarDto.BarName, Is.EqualTo(defaultBar.BarName));
            Assert.That(result, Is.TypeOf <CreatedResult>());
        }
示例#3
0
        public void Add2Bars_GetBarsReturnsListOfAddedBars()
        {
            var barController = new BarController(_uow, _mapper);

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

            var secondBarController = CreateBarController();
            var retrieveResult      = secondBarController.GetBestBars();
            var retrievedObject     = (retrieveResult as OkObjectResult).Value as List <BarSimpleDto>;

            Assert.That(retrieveResult, Is.TypeOf <OkObjectResult>());
            Assert.That(retrievedObject.Count, Is.EqualTo(2));
            Assert.That(retrievedObject[0].BarName, Is.EqualTo("Bar2"));
            Assert.That(retrievedObject[1].BarName, Is.EqualTo("Bar1"));
        }
示例#4
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.
        }
示例#5
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));
        }
示例#6
0
        public void AddIdenticalBars_ControllerReturnsError_DuplicateKey()
        {
            var barController = new BarController(_uow, _mapper);

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

            Assert.That(result2, Is.TypeOf <BadRequestResult>());
            Assert.That(result1, Is.TypeOf <CreatedResult>());
        }
示例#7
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));
        }
示例#8
0
        public void AddBarToDatabase_InvalidModel_BarNotAdded()
        {
            var barController = new BarController(_uow, _mapper);
            var name          = "Only a barname is insufficient!";

            var addResult = barController.AddBar(new BarDto()
            {
                BarName = name
            });

            // To mimic MVC behavior a new controller is instantiated, with a new UnitOfWork
            // The bar is not added to database, but is saved in _uow's memory.
            var secondBarController = CreateBarController();

            var retrievedResult = secondBarController.GetBar(name);

            Assert.That(addResult, Is.TypeOf <BadRequestResult>());
            Assert.That(retrievedResult, Is.TypeOf <NotFoundResult>());
        }
示例#9
0
        public void AddBarToDatabase_BarIsAddedAndCanBeRetrieved()
        {
            var barName       = "TestBar";
            var barController = new BarController(_uow, _mapper);
            var addResult     = barController.AddBar(new BarDto()
            {
                BarName  = barName, AvgRating = 3.4, ShortDescription = "SD",
                AgeLimit = 18, CVR = 1235, Image = "png.jpg", LongDescription = "short",
                Address  = "123 street", Email = "*****@*****.**", Educations = "IKT", PhoneNumber = 0000,
            });

            var secondBarController = CreateBarController();
            var retrievedResult     = secondBarController.GetBar(barName);
            var retrievedObject     = (retrievedResult as OkObjectResult).Value as BarDto;

            Assert.That(addResult, Is.TypeOf <CreatedResult>());
            Assert.That(retrievedResult, Is.TypeOf <OkObjectResult>());
            Assert.That(retrievedObject.BarName, Is.EqualTo(barName));
        }