Exemple #1
0
        public void GetDataSourceItem_no_datasource_set_returns_null()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();

            // Act
            var result = testHarness.GlassUserControl.GetDataSourceItem <StubClass>();

            // Assert
            result.Should().BeNull();
            testHarness.SitecoreContext.Received(0).GetItem <StubClass>(Arg.Any <string>());
        }
        public void GetRenderingParameters_returns_if_empty_string_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();

            testHarness.RenderingContext.GetRenderingParameters().Returns(String.Empty);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters <StubClass>();

            // Assert
            Assert.IsNull(result);
        }
        public void Model_returns_from_context_item_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            StubClass expected = new StubClass();
            testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            result.Should().Be(expected);
        }
        public void GetRenderingParameters_returns_if_null_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();

            testHarness.RenderingContext.GetRenderingParameters().Returns(null as string);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters <StubClass>();

            // Assert
            result.Should().BeNull();
        }
        public void GetContextItem_returns_successfully()
        {
            // Arrange
            var       testHarness = new GlassUserControlTestHarness();
            StubClass expected    = new StubClass();

            testHarness.SitecoreContext.GetCurrentItem <StubClass>().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetContextItem <StubClass>();

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Model_can_be_set_successfully()
        {
            // Arrange
            var       testHarness = new GlassUserControlTestHarness();
            StubClass expected    = new StubClass();

            testHarness.GlassUserControl.Model = expected;

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemple #7
0
        public void DataSource_returns_from_rendering_context_successfully()
        {
            // Arrange
            var          testHarness = new GlassUserControlTestHarness();
            const string expected    = "data source";

            testHarness.RenderingContext.GetDataSource().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.DataSource;

            // Assert
            result.Should().Be(expected);
        }
Exemple #8
0
        public void RenderingParameters_returns_from_rendering_context_successfully()
        {
            // Arrange
            var          testHarness = new GlassUserControlTestHarness();
            const string expected    = "rendering";

            testHarness.RenderingContext.GetRenderingParameters().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.RenderingParameters;

            // Assert
            result.Should().Be(expected);
        }
Exemple #9
0
        public void GetLayoutItem_returns_context_successfully()
        {
            // Arrange
            var       testHarness = new GlassUserControlTestHarness();
            StubClass expected    = new StubClass();

            testHarness.SitecoreContext.GetCurrentItem <StubClass>().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetLayoutItem <StubClass>();

            // Assert
            result.Should().Be(expected);
        }
Exemple #10
0
        public void Model_can_be_set_successfully()
        {
            // Arrange
            var       testHarness = new GlassUserControlTestHarness();
            StubClass expected    = new StubClass();

            testHarness.GlassUserControl.Model = expected;

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            result.Should().Be(expected);
        }
        public void Model_returns_from_data_source_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            StubClass expected = new StubClass();
            string dataSourceId = Guid.NewGuid().ToString();

            testHarness.RenderingContext.GetDataSource().Returns(dataSourceId);
            testHarness.SitecoreContext.GetItem<StubClass>(dataSourceId, testHarness.GlassUserControl.IsLazy, testHarness.GlassUserControl.InferType).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            result.Should().Be(expected);
        }
Exemple #12
0
        public void GetLayoutItem_returns_data_source_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();

            testHarness.RenderingContext.GetDataSource().Returns("fred");
            StubClass expected = new StubClass();

            testHarness.SitecoreContext.GetItem <StubClass>("fred").Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetLayoutItem <StubClass>();

            // Assert
            result.Should().Be(expected);
        }
Exemple #13
0
        public void Model_returns_from_data_source_successfully()
        {
            // Arrange
            var       testHarness  = new GlassUserControlTestHarness();
            StubClass expected     = new StubClass();
            string    dataSourceId = Guid.NewGuid().ToString();

            testHarness.RenderingContext.GetDataSource().Returns(dataSourceId);
            testHarness.SitecoreContext.GetItem <StubClass>(dataSourceId, testHarness.GlassUserControl.IsLazy, testHarness.GlassUserControl.InferType).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            result.Should().Be(expected);
        }
Exemple #14
0
        public void RenderingParameters_returns_from_glass_html_successfully()
        {
            // Arrange
            var          testHarness         = new GlassUserControlTestHarness();
            const string renderingParameters = "rendering";

            testHarness.RenderingContext.GetRenderingParameters().Returns(renderingParameters);
            StubClass expected = new StubClass();

            testHarness.GlassHtml.GetRenderingParameters <StubClass>(renderingParameters).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters <StubClass>();

            // Assert
            result.Should().Be(expected);
        }
        public void Editable_returns_from_glass_html_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string expected = "field value";
            StubClass expectedStub = new StubClass();
            testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(expectedStub);

            Expression<Func<StubClass, object>> fieldExpression = x => x.Field;
            testHarness.GlassHtml.Editable(testHarness.GlassUserControl.Model, fieldExpression, null as object).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Editable(fieldExpression);

            // Assert
            result.Should().Be(expected);
        }
Exemple #16
0
        public void RenderImage_returns_from_glass_html_successfully()
        {
            // Arrange
            var          testHarness  = new GlassUserControlTestHarness();
            const string expected     = "superimage";
            StubClass    expectedStub = new StubClass();

            testHarness.SitecoreContext.GetCurrentItem <StubClass>().Returns(expectedStub);

            Expression <Func <StubClass, object> > fieldExpression = x => x.GlassImage;

            testHarness.GlassHtml.RenderImage(testHarness.GlassUserControl.Model, fieldExpression, null, false, false).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.RenderImage(fieldExpression);

            // Assert
            result.Should().Be(expected);
        }
        public void Editable_returns_from_glass_html_successfully()
        {
            // Arrange
            var          testHarness  = new GlassUserControlTestHarness();
            const string expected     = "field value";
            StubClass    expectedStub = new StubClass();

            testHarness.SitecoreContext.GetCurrentItem <StubClass>().Returns(expectedStub);

            Expression <Func <StubClass, object> > fieldExpression = x => x.Field;

            testHarness.GlassHtml.Editable(testHarness.GlassUserControl.Model, fieldExpression, null as object).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Editable(fieldExpression);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemple #18
0
        public void Editable_returns_from_glass_html_with_standard_output_successfully()
        {
            // Arrange
            var          testHarness  = new GlassUserControlTestHarness();
            const string expected     = "field value";
            StubClass    expectedStub = new StubClass();

            testHarness.SitecoreContext.GetCurrentItem <StubClass>().Returns(expectedStub);

            Expression <Func <StubClass, object> > fieldExpression   = x => x.Field;
            Expression <Func <StubClass, string> > defaultExpression = x => "fred";

            testHarness.GlassHtml.Editable(testHarness.GlassUserControl.Model, fieldExpression, defaultExpression, null).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Editable(fieldExpression, defaultExpression);

            // Assert
            result.Should().Be(expected);
        }
        public void Editable_returns_from_glass_html_with_standard_output_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string expected = "field value";
            StubClass expectedStub = new StubClass();
            testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(expectedStub);

            Expression<Func<StubClass, object>> fieldExpression = x => x.Field;
            Expression<Func<StubClass, string>> defaultExpression = x => "fred";

            testHarness.GlassHtml.Editable(testHarness.GlassUserControl.Model, fieldExpression, defaultExpression, null).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.Editable(fieldExpression, defaultExpression);

            // Assert
            Assert.AreEqual(expected, result);

        }
        public void Model_can_be_set_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            StubClass expected = new StubClass();
            testHarness.GlassUserControl.Model = expected;

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
            result.Should().Be(expected);
        }
        public void GetRenderingParameters_returns_if_empty_string_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            testHarness.RenderingContext.GetRenderingParameters().Returns(String.Empty);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters<StubClass>();

            // Assert
            Assert.IsNull(result);
        }
        public void GetDataSourceItem_returns_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            testHarness.RenderingContext.GetDataSource().Returns("fred");
            StubClass expected = new StubClass();
            testHarness.SitecoreContext.GetItem<StubClass>("fred").Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetDataSourceItem<StubClass>();

            // Assert
                        Assert.AreEqual(expected, result);
        }
        public void GetLayoutItem_returns_context_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            StubClass expected = new StubClass();
            testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetLayoutItem<StubClass>();

            // Assert
                        Assert.AreEqual(expected, result);
        }
        public void Model_can_be_set_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            StubClass expected = new StubClass();
            testHarness.GlassUserControl.Model = expected;

            // Act
            var result = testHarness.GlassUserControl.Model;

            // Assert
                        Assert.AreEqual(expected, result);
        }
        public void DataSource_returns_from_rendering_context_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string expected = "data source";
            testHarness.RenderingContext.GetDataSource().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.DataSource;

            // Assert
            result.Should().Be(expected);
        }
        public void RenderingParameters_returns_from_rendering_context_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string expected = "rendering";
            testHarness.RenderingContext.GetRenderingParameters().Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.RenderingParameters;

            // Assert
            result.Should().Be(expected);
        }
        public void RenderingParameters_returns_from_glass_html_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string renderingParameters = "rendering";
            testHarness.RenderingContext.GetRenderingParameters().Returns(renderingParameters);
            StubClass expected = new StubClass();
            testHarness.GlassHtml.GetRenderingParameters<StubClass>(renderingParameters).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters<StubClass>();

            // Assert
            result.Should().Be(expected);
        }
        public void RenderLink_returns_from_glass_html_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            const string expected = "superimage";
            StubClass expectedStub = new StubClass();
            testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(expectedStub);

            Expression<Func<StubClass, object>> fieldExpression = x => x.GlassLink;
            testHarness.GlassHtml.RenderLink(testHarness.GlassUserControl.Model, fieldExpression, null, false, null).Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.RenderLink(fieldExpression);

            // Assert
            result.Should().Be(expected);
        }
        public void GetDataSourceItem_no_datasource_set_returns_null()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();

            // Act
            var result = testHarness.GlassUserControl.GetDataSourceItem<StubClass>();

            // Assert
            result.Should().BeNull();
            testHarness.SitecoreContext.Received(0).GetItem<StubClass>(Arg.Any<string>());
        }
        public void GetLayoutItem_returns_data_source_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            testHarness.RenderingContext.GetDataSource().Returns("fred");
            StubClass expected = new StubClass();
            testHarness.SitecoreContext.GetItem<StubClass>("fred").Returns(expected);

            // Act
            var result = testHarness.GlassUserControl.GetLayoutItem<StubClass>();

            // Assert
            result.Should().Be(expected);
        }
        public void GetRenderingParameters_returns_if_null_successfully()
        {
            // Arrange
            var testHarness = new GlassUserControlTestHarness();
            testHarness.RenderingContext.GetRenderingParameters().Returns(null as string);

            // Act
            var result = testHarness.GlassUserControl.GetRenderingParameters<StubClass>();

            // Assert
            result.Should().BeNull();
        }