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); }
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); }
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); }