コード例 #1
0
        public void SetUp()
        {
            _source = new FakeSource();
            _column = new ColumnBuilder().Build();
            _row    = new RowBuilder().Build();
            _filter = new FakeFilter();
            _view   = new FakeView();

            _project = new Project()
            {
                Sources = new List <Source> {
                    _source
                },
                Columns = new List <Column> {
                    _column
                },
                Rows = new List <Row> {
                    _row
                },
                Filters = new List <Filter> {
                    _filter
                },
                Views = new List <View> {
                    _view
                }
            };

            _dataContext = new DataContext();

            _dataContext.Sources.Add(_source.GetType(), _source);
            _dataContext.Columns.Add(_column);
            _dataContext.Rows.Add(_row);
            _dataContext.Filters.Add(_filter);
            _dataContext.Views.Add(_view.GetType(), _view);
        }
コード例 #2
0
        public async Task Render_returns_email_string_with_img_created_by_view()
        {
            var email = new Email("Test");
            var cid   = email.ImageEmbedder.ReferenceImage("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");

            var mvcViewOptions = new Mock <Microsoft.Extensions.Options.IOptions <MvcViewOptions> >();

            //var tmp = controller.Resolver.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
            //ICompositeViewEngine engine = new CompositeViewEngine(mvcViewOptions.Object);

            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView(_ => _.ViewData[ImageEmbedder.ViewDataKey] != null ? "True" : "False");

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view));

            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(email);

            actualEmailString.ShouldBe("True");

            viewEngine.Verify();
        }
コード例 #3
0
 public void When_ReadResponse_Succeeds_Results_Are_Returned()
 {
     using (var stream = File.Open(@"Data\\view-response-good.json", FileMode.Open))
     {
         var       handler  = new CouchbaseViewHandler(null, null, null, null, 1, null);
         var       fakeView = new FakeView(handler, stream);
         const int expectedRowCountIsTwentyTwo = 22;
         Assert.AreEqual(expectedRowCountIsTwentyTwo, fakeView.Count());
     }
 }
コード例 #4
0
 public void When_ReadResponse_Succeeds_Results_Are_Returned()
 {
     using (var stream = File.Open(@"Data\\view-response-good.json", FileMode.Open))
     {
         var handler = new CouchbaseViewHandler(null, null, null, null, 1, null);
         var fakeView = new FakeView(handler, stream);
         const int expectedRowCountIsTwentyTwo = 22;
         Assert.AreEqual(expectedRowCountIsTwentyTwo, fakeView.Count());
     }
 }
コード例 #5
0
 public void When_View_Returns_ehostunreach_ReadResponse_Throws_ViewNotFoundException()
 {
     using (var stream = File.Open(@"Data\\view-response-error-ehostunreach.json", FileMode.Open))
     {
         var handler  = new CouchbaseViewHandler(null, null, null, null, 1, null);
         var fakeView = new FakeView(handler, stream);
         foreach (var row in fakeView)
         {
             Assert.IsNotNull(row);
         }
     }
 }
コード例 #6
0
 public void When_View_Returns_case_clause_With_not_found_ReadResponse_Throws_ViewNotFoundException()
 {
     using (var stream = File.Open(@"Data\\view-response-error-case_clause.json", FileMode.Open))
     {
         var handler = new CouchbaseViewHandler(null, null, null, null, 1, null);
         var fakeView = new FakeView(handler, stream);
         foreach (var row in fakeView)
         {
             Assert.IsNotNull(row);
         }
     }
 }
コード例 #7
0
        public void Render_returns_email_string_created_by_view()
        {
            var viewEngines = new Mock<ViewEngineCollection>();
            var view = new FakeView();
            viewEngines.Setup(e => e.FindView(It.IsAny<ControllerContext>(), "Test", null))
                       .Returns(new ViewEngineResult(view, Mock.Of<IViewEngine>()));
            var renderer = new EmailViewRenderer(viewEngines.Object);

            var actualEmailString = renderer.Render(new Email("Test"));

            actualEmailString.ShouldEqual("Fake");
        }
コード例 #8
0
 public void When_View_Returns_BadRpc_ReadResponse_Throws_ViewException()
 {
     using (var stream = File.Open(@"Data\\view-response-error-badrpc.json", FileMode.Open))
     {
         var handler = new CouchbaseViewHandler(null, null, null, null, null);
         var fakeView = new FakeView(handler, stream);
         foreach (var row in fakeView)
         {
             Assert.IsNotNull(row);
         }
     }
 }
コード例 #9
0
        public void Render_returns_email_string_created_by_view()
        {
            var viewEngines = new Mock <ViewEngineCollection>();
            var view        = new FakeView();

            viewEngines.Setup(e => e.FindView(It.IsAny <ControllerContext>(), "Test", null))
            .Returns(new ViewEngineResult(view, Mock.Of <IViewEngine>()));
            var renderer = new EmailViewRenderer(viewEngines.Object);

            var actualEmailString = renderer.Render(new Email("Test"));

            actualEmailString.ShouldEqual("Fake");
        }
コード例 #10
0
        public void SetUp()
        {
            _views = new Dictionary <Type, View>();
            _view  = new FakeView();

            _mockContext = new Mock <IDataContext>();
            _mockContext.Setup(p => p.Views).Returns(_views);

            _mockFactory = new Mock <IViewFactory>();
            _mockFactory.Setup(p => p.Create <FakeView>())
            .Returns(_view);

            _repository = new ViewRepository(
                _mockContext.Object,
                _mockFactory.Object);
        }
コード例 #11
0
    public void Subscription_Test()
    {
        var someServiceMock = new Mock <ISomeDomainService>();
        var viewMock        = new Mock <IView>();
        //Setup your viewMock here
        var          someView    = new FakeView(viewMock.Object);
        EventHandler initHandler = null;

        someView.Subscription += (n, h) => { if ((nameof(someView.Init)).Equals(n))
                                             {
                                                 initHandler = h;
                                             }
        };
        Assert.IsNull(initHandler);
        var presenter = new SomePresenter(someServiceMock.Object, someView);

        Assert.IsNotNull(initHandler);
        Assert.AreEqual("OnInit", initHandler?.Method.Name);
    }
コード例 #12
0
        public async Task Render_returns_email_string_created_by_view()
        {
            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view));

            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(new Email("Test"));

            actualEmailString.ShouldBe("Fake");

            viewEngine.Verify();
        }
コード例 #13
0
        public async Task Render_returns_email_string_created_by_view_generic_host()
        {
            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view)).Verifiable();

            var logger                       = new Mock <ILogger <TemplateService> >();
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            var hostingEnvironment           = new Mock <Microsoft.Extensions.Hosting.IHostEnvironment>();
            ITemplateService templateService = new TemplateService(logger.Object, viewEngine.Object, serviceProvider.Object, tempDataProvider.Object, hostingEnvironment.Object);
            var renderer                     = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(new Email("Test"));

            actualEmailString.ShouldBe("Fake");

            viewEngine.Verify();
        }
コード例 #14
0
        public void TestSerializeOtherViewShouldThrowException()
        {
            var view = new FakeView();

            Assert.That(() => _serializer.Serialize(view), Throws.ArgumentException);
        }