public GetDriverByName ( string name ) : IDriver | ||
name | string | |
return | IDriver |
public void GetDriverByNameValid() { IDriver driverToFind = new Driver { FirstName = "Dave", LastName = "Grayson", }; //Arrange var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.GetByName(driverToFind.FullName).Returns(driverToFind); //Act var driverListViewModel = new DriverModel(driverDataProvider); var result = driverListViewModel.GetDriverByName(driverToFind.FullName); //Assert Assert.IsNotNull(result); Assert.AreEqual(driverToFind.FirstName, result.FirstName); Assert.AreEqual(driverToFind.LastName, result.LastName); }
public void GetDriverByNameEmptyName() { IDriver result = null; //Arrange var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.GetByName(Arg.Any<string>()).Returns(x => null); //Act var driverListViewModel = new DriverModel(driverDataProvider); try { result = driverListViewModel.GetDriverByName(string.Empty); Assert.Fail("Exception should be thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); Assert.AreEqual(ex.Message, "Name Cannot Be Empty"); } //Assert Assert.IsNull(result); }
public void GetDriverByNameUnknownDriver() { IDriver result = null; IDriver driverToFind = new Driver { FirstName = "Dave", LastName = "Grayson", }; //Arrange var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.GetByName(driverToFind.FullName).Returns(x => null); //Act var driverListViewModel = new DriverModel(driverDataProvider); result = driverListViewModel.GetDriverByName(driverToFind.FullName); //Assert Assert.IsNull(result); }