public void WhenCallingGetOrCreateUserWithNoMatchingUser_ThenUserIsReturned()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Create(It.IsAny<MileageStats.Model.User>()))
                .Callback<MileageStats.Model.User>(user => user.UserId = 12);

            Model.User userToReturn = null;
            userRepositoryMock.Setup(u => u.GetByAuthenticatedId(It.IsAny<string>())).Returns(userToReturn);
            userRepositoryMock.Setup(u => u.Create(It.IsAny<Model.User>()))
                .Callback<MileageStats.Model.User>(user => user.UserId = 12);

            var services = new UserServices(userRepositoryMock.Object);

            User createdUser = services.GetOrCreateUser("claimedId");

            Assert.Equal(12, createdUser.UserId);
        }
Exemplo n.º 2
0
 public static Mock<HttpPostedFileBase> MockPhotoStream()
 {
     var photoStream = new Mock<HttpPostedFileBase>();
     photoStream.Setup(x => x.InputStream).Returns(CreateImageStream());
     photoStream.Setup(x => x.ContentType).Returns("stuff");
     return photoStream;
 }
        public void WhenGettingCountryListAndRepositoryThrows_ThenWrapsException()
        {
            var countryRepositoryMock = new Mock<ICountryRepository>();
            countryRepositoryMock.Setup(c => c.GetAll()).Throws<InvalidOperationException>();
            var services = new CountryServices(countryRepositoryMock.Object);

            var ex = Assert.Throws<BusinessServicesException>(() => services.GetCountriesAndRegionsList());
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
        public void WhenCreatingUser_ThenDelegatesToUserRepository()
        {
            var userRepositoryMock = new Mock<IUserRepository>();

            var services = new UserServices(userRepositoryMock.Object);

            services.CreateUser(new User() {AuthorizationId = "authId"});

            userRepositoryMock.Verify(r => r.Create(It.IsAny<MileageStats.Model.User>()), Times.Once());
        }
        public void WhenGettingCountryListAndRepositoryReturnsNoRecords_ThenReturnsEmptyCollection()
        {
            var countryRepositoryMock = new Mock<ICountryRepository>();
            countryRepositoryMock.Setup(c => c.GetAll()).Returns(new List<Country>());
            var services = new CountryServices(countryRepositoryMock.Object);

            var countries = services.GetCountriesAndRegionsList();

            Assert.Empty(countries);
        }
        public void WhenGettingCountryList_ThenReturnsCountryNames()
        {
            var countryRepositoryMock = new Mock<ICountryRepository>();
            countryRepositoryMock.Setup(c => c.GetAll()).Returns(new List<Country>() {new Country()});
            var services = new CountryServices(countryRepositoryMock.Object);

            var countries = services.GetCountriesAndRegionsList();

            Assert.NotNull(countries);
            Assert.Equal(1, countries.Count);
        }
        public void WhenGettingUser_ThenReturnsUser()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            var dataUser = new Model.User {UserId = 1, DisplayName = "test"};

            userRepositoryMock
                .Setup(ur => ur.GetByAuthenticatedId(It.IsAny<string>()))
                .Returns(dataUser);

            var services = new UserServices(userRepositoryMock.Object);

            var returnedUser = services.GetUserByClaimedIdentifier("something");

            Assert.NotNull(returnedUser);
            Assert.Equal("test", returnedUser.DisplayName);
        }
        public void WhenCallingGetOrCreateUserWithMatchingUser_ThenExistingUserIsReturned()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Create(It.IsAny<MileageStats.Model.User>()))
                .Callback<MileageStats.Model.User>(user => user.UserId = 12);
            string claimedId = "claimedId";

            Model.User userToReturn = new Model.User() {AuthorizationId = claimedId};
            userRepositoryMock.Setup(u => u.GetByAuthenticatedId(It.IsAny<string>())).Returns(userToReturn);

            var services = new UserServices(userRepositoryMock.Object);

            User createdUser = services.GetOrCreateUser(claimedId);

            userRepositoryMock.Verify(u => u.Create(It.IsAny<Model.User>()), Times.Never());
            Assert.Equal(claimedId, createdUser.AuthorizationId);
        }
 public WhenAddingFillup()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
     _fillupRepositoryMock = new Mock<IFillupRepository>();
     _vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle" };
 }
 public WhenUpdatingVehicle()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
     _photoRepo = new Mock<IVehiclePhotoRepository>();
 }
Exemplo n.º 11
0
 public WhenGettingVehicles()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
 }
Exemplo n.º 12
0
 public WhenCanAddVehicle()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
     _manufacturerRepo = new Mock<IVehicleManufacturerRepository>();
 }
Exemplo n.º 13
0
        private static CanValidateVehicleYearMakeAndModel MockCanValidateVehicleYearMakeAndModel(VehicleFormModel vehicleForm)
        {
            var subhandler = new Mock<CanValidateVehicleYearMakeAndModel>(null);

            subhandler
                .Setup(h => h.Execute(vehicleForm))
                .Returns(Enumerable.Empty<ValidationResult>());

            return subhandler.Object;
        }
Exemplo n.º 14
0
 public WhenGettingFillups()
 {
     _userServicesMock = new Mock<IUserServices>();
     _vehicleRepo = new Mock<IVehicleRepository>();
     _fillupRepositoryMock = new Mock<IFillupRepository>();
 }
 public WhenDeletingVehicle()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
 }
 public WhenCanAddFillup()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
     _fillupRepo = new Mock<IFillupRepository>();
 }
Exemplo n.º 17
0
        public void WhenCreatingUser_ThenReturnsUpdatedUserWithUserId()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Create(It.IsAny<MileageStats.Model.User>()))
                .Callback<MileageStats.Model.User>(user => user.UserId = 12);
            var services = new UserServices(userRepositoryMock.Object);

            User servicesUser = new User() {AuthorizationId = "authId"};
            Assert.Equal(0, servicesUser.UserId);
            User createdUser = services.CreateUser(servicesUser);

            Assert.Equal(12, createdUser.UserId);
        }
Exemplo n.º 18
0
        public void WhenGettingUserAndRepositoryThrows_ThenWrapsException()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.GetByAuthenticatedId(It.IsAny<string>()))
                .Throws<InvalidOperationException>();

            var services = new UserServices(userRepositoryMock.Object);

            var ex = Assert.Throws<BusinessServicesException>(() => services.GetUserByClaimedIdentifier("test"));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
 public WhenUpdatingVehicleSortOrder()
 {
     _vehicleRepo = new Mock<IVehicleRepository>();
 }
Exemplo n.º 20
0
        public void WhenUpdatingUserAndRepositoryThrows_ThenWrapsException()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Update(It.IsAny<MileageStats.Model.User>()))
                .Throws<InvalidOperationException>();

            var services = new UserServices(userRepositoryMock.Object);

            var ex = Assert.Throws<BusinessServicesException>(
                () => services.UpdateUser(new User() {AuthorizationId = "authId"}));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
 public WhenGettingReminders()
 {
     _reminderRepository = new Mock<IReminderRepository>();
 }
 public WhenAddingReminder()
 {
     _vehicleRepository = new Mock<IVehicleRepository>();
     _reminderRepository = new Mock<IReminderRepository>();
 }
Exemplo n.º 23
0
        public void WhenUpdatingUser_ThenDelegatesToUserRepository()
        {
            var userRepositoryMock = new Mock<IUserRepository>();
            userRepositoryMock.Setup(u => u.Create(It.IsAny<MileageStats.Model.User>()))
                .Callback<MileageStats.Model.User>(u => u.UserId = 12);

            var services = new UserServices(userRepositoryMock.Object);

            User user = new User() {AuthorizationId = "authId"};
            services.CreateUser(user);
            user.AuthorizationId = "newAuthId";
            services.UpdateUser(user);

            userRepositoryMock.Verify(r => r.Update(It.IsAny<MileageStats.Model.User>()), Times.Once());
        }