コード例 #1
0
        public void ThatGetScriptFromFileReturnsString()
        {
            BogusDatabaseMock constructorTest = new BogusDatabaseMock();

            ConfigurationService configurationService = new ConfigurationService();

            configurationService.SetupDatabaseType();
            Mock <IFileService> fileServiceMock = new Mock <IFileService>(MockBehavior.Strict);

            string scriptFileName = "MyScript.sql";
            string fileContents   = "File Contents";
            string filePath       = Path.Combine(configurationService.DatabaseScriptPath, scriptFileName);
            string passedFile     = string.Empty;
            bool   useCache       = false;

            fileServiceMock.Setup(f => f.GetFileContents(It.IsAny <string>(), It.IsAny <bool>()))
            .Callback(
                (string f, bool c) =>
            {
                passedFile = f;
                useCache   = c;
            }).Returns(fileContents);

            IDatabaseService databaseService = new BogusDatabaseMock(
                configurationService,
                fileServiceMock.Object,
                new TokenReplacer());

            string result = databaseService.GetScriptFromFile(scriptFileName);

            Assert.AreEqual(fileContents, result);
            Assert.AreEqual(passedFile, filePath);
            Assert.IsTrue(useCache);
        }
コード例 #2
0
        public void ThatGetAppliedChangesReturnsChangelog()
        {
            ConfigurationService configurationService = new ConfigurationService();

            configurationService.SetupDatabaseType();
            Mock <IFileService> fileServiceMock = new Mock <IFileService>(MockBehavior.Strict);

            string fileContents = "File Contents";

            fileServiceMock.Setup(f => f.GetFileContents(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(fileContents)
            .Verifiable();

            BogusDatabaseMock databaseService = new BogusDatabaseMock(
                configurationService,
                fileServiceMock.Object,
                new TokenReplacer(configurationService));

            databaseService.DataSetToReturn = this.GetDataset();

            IDictionary <decimal, IChangeLog> result = databaseService.GetAppliedChanges();

            fileServiceMock.Verify(f => f.GetFileContents(It.IsAny <string>(), It.IsAny <bool>()), Times.Exactly(2));

            Assert.IsTrue(databaseService.ScriptsRunNames.Contains(DatabaseScriptEnum.EnsureChangeLogExists));
            Assert.IsTrue(databaseService.ScriptsRunNames.Contains(DatabaseScriptEnum.GetChangeLog));
            Assert.AreEqual(result.Count, 5);
        }