public ActionResult Recommendation(
            RenderModel model,
            int id,
            string name)
        {
            IPublishedContent recommendationRespository = Helper.TypedContentAtRoot().FirstOrDefault()
                                                          .FirstChild(x => x.DocumentTypeAlias == Constants.NodeAlias.RECOMMENDATIONS_REPOSITORY);

            RecommendationModel recommendationModel = RecommendationFactory.Create(model.Content, recommendationRespository, Services.ContentService, Site.IsEnglish, isDetails: true);

            // make sure the productName for the route matches the encoded product name
            string expectedName = recommendationModel.HeadLine.ToSeoUrl();

            string actualName = (name ?? "").ToLower();

            // permanently redirect to the correct URL
            if (expectedName != actualName)
            {
                return(RedirectToActionPermanent(Constants.Controllers.Recommendation.NAME,
                                                 Constants.Controllers.Recommendation.Actions.RECOMMENDATION,
                                                 new
                {
                    id = recommendationModel.Id,
                    name = expectedName
                }));
            }

            return(CurrentTemplate(recommendationModel));
        }
        public void RecommendationFactory_GetRecommendation_WithValidPriceRangeAndUsage_ShouldReturnRecommendation()
        {
            var usage        = new[] { Usage.General, Usage.Business };
            var priceCap     = 400.00M;
            var repository   = new Mock <ComponentRepository>();
            var engineSource = new Mock <RecommendationEngineSupplier>();

            engineSource
            .Setup(x => x.GetComponentRecommendationEngine(
                       It.IsAny <IComponentRepository>(),
                       It.IsAny <ComponentType>()))
            .Returns((IComponentRepository r, ComponentType t) =>
                     GetFakeEngineFor(t, usage, priceCap));

            var sut    = new RecommendationFactory(repository.Object, engineSource.Object);
            var result = sut.GetRecommendation(usage, priceCap);

            engineSource.VerifyAll();

            Assert.IsInstanceOfType(result, typeof(Recommendation));

            Assert.IsTrue(result.Processor.Category == ComponentType.Processor);
            Assert.IsTrue(result.HardDiskDrive.Category == ComponentType.HardDrive);
            Assert.IsTrue(result.RamKit.Category == ComponentType.RAM);
            Assert.IsTrue(result.VideoCard.Category == ComponentType.VideoCard);
            Assert.IsTrue(result.TotalPrice <= priceCap);
        }
Beispiel #3
0
        public void Live_GetComponentByPriceAndQuality_ForGeneral()
        {
            var priceCap = 500.00M;

            var sut    = new RecommendationFactory(liveRepo, new RecommendationEngineSupplier());
            var result = sut.GetRecommendation(new Usage[] { Usage.General }, priceCap);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Processor);
            Assert.IsNotNull(result.RamKit);
            Assert.IsNotNull(result.HardDiskDrive);
            Assert.IsNotNull(result.VideoCard);
            Assert.IsTrue(result.TotalPrice <= priceCap);
        }
Beispiel #4
0
        public void Live_GetComponentByPriceAndQuality_ForGaming_ImpossiblePrice_ShouldReturnNullRecommendation()
        {
            var priceCap = 10.00M;

            var sut    = new RecommendationFactory(liveRepo, new RecommendationEngineSupplier());
            var result = sut.GetRecommendation(new Usage[] { Usage.Gaming }, priceCap);

            Assert.IsNotNull(result);
            Assert.IsNull(result.Processor);
            Assert.IsNull(result.RamKit);
            Assert.IsNull(result.HardDiskDrive);
            Assert.IsNull(result.VideoCard);
            Assert.IsTrue(result.TotalPrice == 0.00M);
        }
        public void RecommendationFactory_GetRecommendation_WithInvalidPriceRange_ShouldReturnNullRecommendation()
        {
            var usage        = new[] { Usage.General, Usage.Business };
            var highPrice    = 10.00M;
            var repository   = new Mock <ComponentRepository>();
            var engineSource = new Mock <RecommendationEngineSupplier>();

            engineSource
            .Setup(x => x.GetComponentRecommendationEngine(It.IsAny <ComponentRepository>(), It.IsAny <ComponentType>()))
            .Returns(new NullRecommendationEngine(repository.Object));

            var sut    = new RecommendationFactory(repository.Object, engineSource.Object);
            var result = sut.GetRecommendation(usage, highPrice);

            Assert.IsInstanceOfType(result, typeof(Recommendation));

            Assert.IsNull(result.HardDiskDrive);
            Assert.IsNull(result.Processor);
            Assert.IsNull(result.RamKit);
            Assert.IsNull(result.VideoCard);
        }
 public ComponentsController(IComponentRepository repository, RecommendationFactory factory)
 {
     componentRepository   = repository;
     recommendationFactory = factory;
 }