コード例 #1
0
        public void EntityReader_ShouldDeserializeEntity()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new EntityReader(_dateTimeWrapperMock.Object, _loggerMock.Object, _databaseMock.Object);

            // Act
            var result = reader.ReadEntity(_json);

            // Assert
            result.Should().BeEquivalentTo(_expectedEntity);
        }
コード例 #2
0
        public void EntityReader_ShouldLogDeserializationOfEntity()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new EntityReader(_dateTimeWrapperMock.Object, _loggerMock.Object, _databaseMock.Object);

            // Act
            reader.ReadEntity(_json);

            // Assert
            _loggerMock.Verify(x => x.WriteLine($"Entity deserialized. Id: {_expectedEntity.Id}, Name: {_expectedEntity.Name}, Type: {_expectedEntity.Type}, Timestamp: {_expectedEntity.Timestamp}"));
        }
コード例 #3
0
        public void EntityReader_ShouldPassValidation()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            _databaseMock.Setup(x => x.IsValidationEnabled()).Returns(true);
            var reader = new EntityReader(_dateTimeWrapperMock.Object, _loggerMock.Object, _databaseMock.Object);

            // Act
            reader.ReadEntity(_json);

            // Assert
            _loggerMock.Verify(x => x.WriteLine($"Validation result: {true}"));
        }
コード例 #4
0
ファイル: Example2Tests.cs プロジェクト: rsobon/TestableCode
        public void EntityReader_ShouldDeserializeEntity()
        {
            // Arrange
            var expectedEntity = new Entity
            {
                Id   = 1,
                Name = "Test Name",
                Type = EntityType.NotAwesomeType
            };
            var reader = new EntityReader();

            // Act
            var result = reader.ReadEntity(_json);

            // Assert
            Assert.AreEqual(expectedEntity.Id, result.Id);
            Assert.AreEqual(expectedEntity.Name, result.Name);
            Assert.AreEqual(expectedEntity.Type, result.Type);
        }