Esempio n. 1
0
        public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenCorrectRuntimeType_ReturnsProvidedValue()
        {
            // Arrange
            object expected = "Just some content";

            ContentContainer <ContentType> sut = new ContentContainer <ContentType>(ContentType.Type1, (t) => expected);

            // Act
            object actual = sut.GetContentAs <string>();

            // Assert
            actual.Should().BeSameAs(expected);
        }
Esempio n. 2
0
        public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenWrongRuntimeType_ThrowsArgumentException()
        {
            // Arrange
            object expected = "Just some content";

            ContentContainer <ContentType> sut = new ContentContainer <ContentType>(ContentType.Type1, (t) => expected);

            // Act
            ContentTypeException contentTypeException = Assert.Throws <ContentTypeException>(() => sut.GetContentAs <int>());

            // Assert
            contentTypeException.Should().NotBeNull();
            contentTypeException.Message.Should().Be("Cannot cast content to provided type as TContent: System.Int32");
            contentTypeException.InnerException.Should().NotBeNull()
            .And.BeOfType <InvalidCastException>($"{nameof(ContentTypeException)} should happen when an invalid cast is attempted.");
        }