Inheritance: IDriver
コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }