Exemplo n.º 1
0
        public void GetDatabase_DatabaseServiceReturnsNull_ReturnsNull()
        {
            // Arrange
            string dbName = "testDatabase";

            // Arrange - mock dbService
            this._dbServiceMock.Setup(s => s.GetDatabase(dbName))
            .Returns((Database)null);

            // Arrange - create target
            DbWcfService target = new DbWcfService(this._dbServiceMock.Object);

            // Act
            DatabaseDto db = target.GetDatabase(dbName);

            // Assert
            Assert.IsNull(db);
        }
Exemplo n.º 2
0
        public void GetDatabase_DatabaseServiceThrowsExceptions_ForwardsException()
        {
            // Arrange
            string dbName = "testDatabase";

            Exception exception = new Exception();

            // Arrange - mock dbService
            this._dbServiceMock.Setup(s => s.GetDatabase(dbName))
            .Throws(exception);

            // Arrange - create target
            DbWcfService target = new DbWcfService(this._dbServiceMock.Object);

            // Act
            Exception ex = Assert.Throws <Exception>(() => target.GetDatabase(dbName));

            Assert.AreSame(exception, ex);
        }
Exemplo n.º 3
0
        public void GetDatabase_DatabaseServiceReturnsDatabase_ReturnsDatabaseDto()
        {
            // Arrange
            Database database = new Database
            {
                Name = "someDatabase", Tables = { { "firstTable", new Table() }, { "secondTable", new Table() } }
            };

            // Arrange - mock dbService
            this._dbServiceMock.Setup(s => s.GetDatabase(database.Name))
            .Returns(database);

            // Arrange - create target
            DbWcfService target = new DbWcfService(this._dbServiceMock.Object);

            // Act
            DatabaseDto dbDto = target.GetDatabase(database.Name);

            // Assert
            Assert.IsNotNull(dbDto);

            Assert.AreEqual(dbDto.Name, database.Name);
            Assert.AreEqual(dbDto.TableNames, database.Tables.Keys);
        }