public void GetAllDriversValid() { //Arrange var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.GetAll() .Returns(new List<IDriver> { new Driver{FirstName = "Peter",LastName = "Davidson"} }); //Act var driverListViewModel = new DriverModel(driverDataProvider); var result = driverListViewModel.GetAllDrivers(); //Assert Assert.AreEqual(1, result.Count); }
public void GetDriverByIDValid() { IDriver driverToFind = new Driver { ID = 1, FirstName = "Dave", LastName = "Grayson", }; //Arrange var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.GetById(driverToFind.ID).Returns(driverToFind); //Act var driverListViewModel = new DriverModel(driverDataProvider); var result = driverListViewModel.GetDriverDetails(driverToFind.ID); //Assert Assert.IsNotNull(result); Assert.AreEqual(driverToFind.ID, result.ID); 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 UpdateDriverValid() { //Arrange IDriver driverToSave = new Driver { ID = 1, FirstName = "Dave", LastName = "Grayson", Country = "Scotland", CardNumber = "098765789" }; var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.Update(driverToSave).Returns(OpResult.Success); //Act var driverModel = new DriverModel(driverDataProvider); OpResult result = driverModel.UpdateDriver(driverToSave); //Assert Assert.AreEqual(OpResult.Success, result); }
public void UpdateDriverInvalidNullDriver() { var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.Update(null).Returns(OpResult.NullParameter); //Act var driverModel = new DriverModel(driverDataProvider); OpResult result = driverModel.UpdateDriver(null); //Assert Assert.AreEqual(OpResult.Success, result); }
public void SaveDriverInvalidDriverDetails() { IDriver driverToSave = new Driver { ID = 1, FirstName = string.Empty, LastName = "Grayson", Country = "Scotland", CardNumber = "098765789" }; var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.Save(driverToSave).Returns(OpResult.Success); //Act var driverModel = new DriverModel(driverDataProvider); OpResult result = driverModel.SaveDriver(driverToSave); //Assert Assert.AreEqual(OpResult.InvalidParameters, result); }
public void SaveDriverInvalidDriverAlreadyExists() { IDriver driverToSave = new Driver { ID = 1, FirstName = "Dave", LastName = "Grayson", Country = "Scotland", CardNumber = "098765789" }; var driverDataProvider = Substitute.For<IDriverDataProvider>(); driverDataProvider.Save(driverToSave).Returns(OpResult.ObjectExists); //Act var driverModel = new DriverModel(driverDataProvider); OpResult result = driverModel.SaveDriver(driverToSave); //Assert Assert.AreEqual(OpResult.ObjectExists, 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); }