public void Methods_delegate_to_configured_store_creator() { var model = Mock.Of <IModel>(); var creatorMock = new Mock <RelationalDataStoreCreator>(); creatorMock.Setup(m => m.Exists()).Returns(true); creatorMock.Setup(m => m.HasTables()).Returns(true); creatorMock.Setup(m => m.EnsureCreated(model)).Returns(true); creatorMock.Setup(m => m.EnsureDeleted(model)).Returns(true); var configurationMock = new Mock <DbContextConfiguration>(); var connectionMock = new Mock <RelationalConnection>(); var dbConnectionMock = new Mock <DbConnection>(); configurationMock.Setup(m => m.DataStoreCreator).Returns(creatorMock.Object); configurationMock.Setup(m => m.Model).Returns(model); configurationMock.Setup(m => m.Connection).Returns(connectionMock.Object); configurationMock.Setup(m => m.LoggerFactory).Returns(new LoggerFactory()); connectionMock.SetupGet(m => m.DbConnection).Returns(dbConnectionMock.Object); dbConnectionMock.SetupGet(m => m.Database).Returns("MyDb"); var database = new RelationalDatabase(configurationMock.Object); Assert.True(database.Exists()); creatorMock.Verify(m => m.Exists(), Times.Once); database.Create(); creatorMock.Verify(m => m.Create(), Times.Once); database.CreateTables(); creatorMock.Verify(m => m.CreateTables(model), Times.Once); Assert.True(database.HasTables()); creatorMock.Verify(m => m.HasTables(), Times.Once); database.Delete(); creatorMock.Verify(m => m.Delete(), Times.Once); Assert.True(database.EnsureCreated()); creatorMock.Verify(m => m.EnsureCreated(model), Times.Once); Assert.True(database.EnsureDeleted()); creatorMock.Verify(m => m.EnsureDeleted(model), Times.Once); Assert.Same(connectionMock.Object, database.Connection); }
public void Methods_delegate_to_configured_store_creator() { var model = Mock.Of<IModel>(); var creatorMock = new Mock<RelationalDataStoreCreator>(); creatorMock.Setup(m => m.Exists()).Returns(true); creatorMock.Setup(m => m.HasTables()).Returns(true); creatorMock.Setup(m => m.EnsureCreated(model)).Returns(true); creatorMock.Setup(m => m.EnsureDeleted(model)).Returns(true); var connection = Mock.Of<RelationalConnection>(); var configurationMock = new Mock<DbContextConfiguration>(); configurationMock.Setup(m => m.DataStoreCreator).Returns(creatorMock.Object); configurationMock.Setup(m => m.Model).Returns(model); configurationMock.Setup(m => m.Connection).Returns(connection); var database = new RelationalDatabase(configurationMock.Object); Assert.True(database.Exists()); creatorMock.Verify(m => m.Exists(), Times.Once); database.Create(); creatorMock.Verify(m => m.Create(), Times.Once); database.CreateTables(); creatorMock.Verify(m => m.CreateTables(model), Times.Once); Assert.True(database.HasTables()); creatorMock.Verify(m => m.HasTables(), Times.Once); database.Delete(); creatorMock.Verify(m => m.Delete(), Times.Once); Assert.True(database.EnsureCreated()); creatorMock.Verify(m => m.EnsureCreated(model), Times.Once); Assert.True(database.EnsureDeleted()); creatorMock.Verify(m => m.EnsureDeleted(model), Times.Once); Assert.Same(connection, database.Connection); }