Beispiel #1
0
        public void ThatGetScriptFromFileReturnsString()
        {
            BogusDatabaseMock constructorTest = new BogusDatabaseMock();

            IConfigurationService configurationService = new ConfigurationService();
            var 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.That(fileContents, Is.EqualTo(result));
            Assert.That(passedFile, Is.EqualTo(filePath));
            Assert.That(useCache, Is.EqualTo(true));
        }
Beispiel #2
0
        public void ThatGetAppliedChangesReturnsChangelog()
        {
            IConfigurationService configurationService = new ConfigurationService();
            var 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());

            databaseService.DataSetToReturn = this.GetDataset();

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

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

            Assert.That(databaseService.ScriptsRunNames.Contains(DatabaseScriptEnum.EnsureChangeLogExists), Is.True);
            Assert.That(databaseService.ScriptsRunNames.Contains(DatabaseScriptEnum.GetChangeLog), Is.True);
            Assert.That(result.Count, Is.EqualTo(5));
        }