Ejemplo n.º 1
0
        public void Save_InvalidActivity_RaisesException(string activity)
        {
            // Arrange
            var sqlClient    = Mock.Of <ISqlClient>();
            var config       = Mock.Of <IConfig>();
            var activityData = new ActivityData(sqlClient, config);

            // Act, Assert
            Assert.Throws <Exception>(() => activityData.Save(activity));
        }
Ejemplo n.º 2
0
        public void Save_InvalidConnectionString_RaisesException()
        {
            // Arrange
            var    sqlClient = Mock.Of <ISqlClient>();
            var    config    = Mock.Of <IConfig>();
            string invalidConnectionString = string.Empty;

            Mock.Get(config)
            .SetupGet(p => p.ActivityDbConnectionString)
            .Returns(invalidConnectionString);

            var activityData = new ActivityData(sqlClient, config);

            // Act, Assert
            Assert.Throws <Exception>(() => activityData.Save("Create a compost pile"));
        }
Ejemplo n.º 3
0
        public void Save_ValidActivity_UpdatesDatabase()
        {
            // Arrange
            var sqlClient = Mock.Of <ISqlClient>();

            Mock.Get(sqlClient)
            .Setup(m => m.ExecuteNonQuery(It.IsAny <string>(), It.IsAny <string>()));

            var config = Mock.Of <IConfig>();

            Mock.Get(config)
            .SetupGet(p => p.ActivityDbConnectionString)
            .Returns("valid-connection-string");

            var activityData = new ActivityData(sqlClient, config);

            // Act
            activityData.Save("Create a compost pile");

            // Assert
            Mock.Get(sqlClient)
            .Verify(m => m.ExecuteNonQuery(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }