public void Add_Schedule()
        {
            var context = new MockContext();
            context.Vehicles.Add(_vehicle);
            var store = new MaintenanceStore(context);

            store.AddWorkItem(1, new Schedule
            {
                Id = 1,
                DistanceInterval = 100,
                Notes = "Test",
                Parts = new List<Part>() { new Part { Id = 1, Cost = 2.00m, Name = "test" } },
                Title = "TestTitle"
            });

            Assert.AreEqual(1, context.Schedules.Count());
            var schedule = context.Schedules.First();
            Assert.AreEqual(1, schedule.Id);
            Assert.AreEqual(100, schedule.DistanceInterval);
            Assert.AreEqual("Test", schedule.Notes);
            Assert.AreEqual("TestTitle", schedule.Title);
            Assert.AreEqual(1, schedule.Parts.Count());
            var part = schedule.Parts.First();
            Assert.AreEqual(1, part.Id);
            Assert.AreEqual(2.00m, part.Cost);
            Assert.AreEqual("test", part.Name);
        }
Пример #2
0
        public void Add_User_With_No_Username()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var userStore = new UserStore(context, encrpytor.Object);

            userStore.AddUser(new User { Username = "" }, "Password");
        }
Пример #3
0
        public void Authenticate_No_User()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var users = new Mock<DbSet<User>>();
            var userStore = new UserStore(context, encrpytor.Object);

            Assert.IsFalse(userStore.Authenticate("test", "test"));
        }
Пример #4
0
        public void Add_Duplicate_Username()
        {
            var context = new MockContext();
            context.Users.Add(
                new User { Username= "******"}
            );
            var encryptor = new Mock<IEncryptor>();
            var userStore = new UserStore(context, encryptor.Object);

            userStore.AddUser(new User { Username = "******" }, "password");
        }
Пример #5
0
        public void Add_Duplicate_Make()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);
            var make = new Make
            {
                Id = 1,
                Name = "cow"
            };
            context.Makes.Add(make);

            make.Id = 2;
            store.AddMake(make);
        }
Пример #6
0
        public void Authenticate_User()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var salt = new byte[] { 1 };
            var password = new byte[] { 1, 2, 3, 4};
            context.Users.Add(new User{
                Username = "******", Password = password, Salt = salt
            });
            encrpytor.Setup(e => e.GetPassword(salt, "test")).Returns(new byte[] { 1, 2, 3, 4 });

            var userStore = new UserStore(context, encrpytor.Object);

            Assert.IsTrue(userStore.Authenticate("test", "test"));
        }
Пример #7
0
        public void Add_Make()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);

            store.AddMake(new Make
            {
                Id = 1,
                Name = "Cowaskai"
            });

            var make = context.Makes.First();
            Assert.AreEqual(1, make.Id);
            Assert.AreEqual("Cowaskai", make.Name);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
Пример #8
0
        public void Add_Duplicate_Model()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);

            var model = new Model()
            {
                Id = 2,
                Make = _make,
                Name = "Klaker"
            };

            context.Models.Add(model);
            model.Id = 3;

            store.AddModel(model);
        }
Пример #9
0
        public void List_Empty_Vehicles()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);

            var result = store.ListVehicles(_user.Username);

            Assert.AreEqual(0, result.Count());
        }
Пример #10
0
        public void Duplicate_Model_Different_Make()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);

            var model = new Model()
            {
                Id = 2,
                Make = _make,
                Name = "Klaker"
            };

            context.Models.Add(model);
            model = new Model()
            {
                Id = 3,
                Name = "Klaker",
                Make = new Make
                {
                    Id = 3,
                    Name = "Suzoooki"
                }
            };

            store.AddModel(model);

            model = context.Models.Last();
            Assert.AreEqual(3, model.Id);
            Assert.AreEqual("Klaker", model.Name);

            var make = model.Make;
            Assert.AreEqual(3, make.Id);
            Assert.AreEqual("Suzoooki", make.Name);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
Пример #11
0
        public void Delete_Vehicle_Wrong_Vehicle()
        {
            var context = new MockContext();
            var vehicle = new Vehicle { Id = 1, User = _user };
            context.Vehicles.Add(vehicle);
            var store = new VehicleStore(context);

            store.DeleteVehicle(2, 2);
        }
Пример #12
0
        public void Delete_Vehicle()
        {
            var context = new MockContext();
            var vehicle = new Vehicle { Id = 1, User = _user};
            context.Vehicles.Add(vehicle);
            var store = new VehicleStore(context);

            store.DeleteVehicle(_user.Id, 1);

            Assert.AreEqual(0, context.Vehicles.Count());
        }
Пример #13
0
        public void Add_Vehicle_Invalid_User()
        {
            var context = new MockContext();
            context.Models.Add(_model);
            context.Users.Add(_user);
            var store = new VehicleStore(context);
            var vehicle = new Vehicle
            {
                Kilometers = 7000,
                Model = context.Models.First(),
                Year = "1991"
            };

            store.AddVehicle("abc", vehicle);
        }
Пример #14
0
        public void Authenticate_User_Wrong_Password()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            context.Users.Add(new User { Username = "******", Password = new byte[] { 1, 2 }});
            var userStore = new UserStore(context, encrpytor.Object);

            Assert.IsFalse(userStore.Authenticate("test", "test"));
        }
        public void Add_Schedule_Invalid_Vehicle()
        {
            var context = new MockContext();
            var store = new MaintenanceStore(context);

            store.AddWorkItem(0, new Schedule());
        }
        public void Add_Task()
        {
            var context = new MockContext();
            context.Vehicles.Add(_vehicle);
            var store = new MaintenanceStore(context);

            store.AddWorkItem(1, new MaintenanceTracker.Domain.Model.Task
            {
                Id = 1,
                Notes = "Test Notes",
                Parts = new List<Part>() { new Part { Id = 1, Cost = 2.00m, Name = "test" } },
                Title = "TestTitle"
            });

            Assert.AreEqual(1, context.Tasks.Count());
            var task = context.Tasks.First();
            Assert.AreEqual(1, task.Id);
            Assert.AreEqual("Test Notes", task.Notes);
            Assert.AreEqual("TestTitle", task.Title);
            Assert.AreEqual(1, task.Parts.Count());
            var part = task.Parts.First();
            Assert.AreEqual(1, part.Id);
            Assert.AreEqual(2.00m, part.Cost);
            Assert.AreEqual("test", part.Name);
        }
        public void List_All_Tasks()
        {
            var context = new MockContext();
            context.Tasks.Add(_tasks[0]);
            context.Tasks.Add(_tasks[1]);
            var store = new MaintenanceStore(context);

            var result = store.GetTasks(_vehicle.Id).ToList();

            Assert.AreEqual(2, result.Count);
            var task1 = result[0];
            Assert.AreEqual(6, task1.Id);
            Assert.AreEqual(_vehicle, task1.Vehicle);
            Assert.AreEqual("Tyre", task1.Title);

            var task2 = result[1];
            Assert.AreEqual(7, task2.Id);
            Assert.AreEqual(_vehicle, task2.Vehicle);
            Assert.AreEqual("Chain", task2.Title);
        }
Пример #18
0
        public void Change_Password()
        {
            var context = new MockContext();
            context.Users.Add(new User
            {
                Username = "******",
                Password = new byte[] {1,2,3,4},
                Salt = new byte[] {1,2}
            });

            var encryptor = new Mock<IEncryptor>();
            encryptor.Setup(e => e.GetSalt()).Returns(new byte[] { 3, 4 });
            encryptor.Setup(e => e.GetPassword(new byte[] { 3, 4 }, "newPassword")).Returns(new byte[] { 5, 6, 7, 8 });

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangePassword("test", "newPassword");

            encryptor.Verify(e => e.GetPassword(new byte[] { 3, 4 }, "newPassword"), Times.Once);
            encryptor.Verify(e => e.GetSalt(), Times.Once);
            var user = context.Users.First();
            Assert.AreEqual("test", user.Username);
            Assert.AreEqual(new byte[] { 5, 6, 7, 8 }, user.Password);
            Assert.AreEqual(new byte[] { 3, 4 }, user.Salt);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
        public void List_All_Schedules()
        {
            var context = new MockContext();
            context.Schedules.Add(_schedules[0]);
            context.Schedules.Add(_schedules[1]);
            var store = new MaintenanceStore(context);

            var result = store.GetSchedules(_vehicle.Id).ToList();

            Assert.AreEqual(2, result.Count);
            var schedule1 = result[0];
            Assert.AreEqual(1, schedule1.Id);
            Assert.AreEqual(_vehicle, schedule1.Vehicle);
            Assert.AreEqual("Oil", schedule1.Title);

            var schedule2 = result[1];
            Assert.AreEqual(2, schedule2.Id);
            Assert.AreEqual(_vehicle, schedule2.Vehicle);
            Assert.AreEqual("Spark Plug", schedule2.Title);
        }
        public void Add_Task_Invalid_Vehicle()
        {
            var context = new MockContext();
            var store = new MaintenanceStore(context);

            store.AddWorkItem(0, new MaintenanceTracker.Domain.Model.Task());
        }
Пример #21
0
        public void Change_Email()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();
            context.Users.Add(new User { Username = "******", Email = "*****@*****.**" });

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangeEmail("test", "*****@*****.**");

            var user = context.Users.First();
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
Пример #22
0
        public void List_Two_Vehicles()
        {
            var context = new MockContext();
            context.Vehicles.Add(new Vehicle
            {
                Id = 1,
                Kilometers = 1337,
                Model = _model,
                User = _user
            });
            context.Vehicles.Add(new Vehicle
            {
                Id = 2,
                Kilometers = 1338,
                Model = _model,
                User = _user
            });
            var store = new VehicleStore(context);

            var result = store.ListVehicles(_user.Username);

            Assert.AreEqual(2, result.Count());
            var vehicle = result.First();
            Assert.AreEqual(1337, vehicle.Kilometers);
            Assert.AreEqual(1, vehicle.Id);
            Assert.AreEqual(_user, vehicle.User);
            Assert.AreEqual(_model, vehicle.Model);
            vehicle = result.Last();
            Assert.AreEqual(1338, vehicle.Kilometers);
            Assert.AreEqual(2, vehicle.Id);
            Assert.AreEqual(_user, vehicle.User);
            Assert.AreEqual(_model, vehicle.Model);
        }
Пример #23
0
        public void Add_Model()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);

            store.AddModel(new Model
            {
                Id = 2,
                Make = _make,
                Name = "Klaker"
            });

            var model = context.Models.First();
            Assert.AreEqual(2, model.Id);
            Assert.AreEqual(_make, model.Make);
            Assert.AreEqual("Klaker", model.Name);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
Пример #24
0
        public void Change_Password_User_Not_Found()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangePassword("test", "newPassword");
        }
Пример #25
0
        public void Add_Valid_Vehicle()
        {
            var context = new MockContext();
            context.Models.Add(_model);
            context.Users.Add(_user);
            var store = new VehicleStore(context);
            var vehicle = new Vehicle
            {
                Kilometers = 7000,
                Model = context.Models.First(),
                Year = "1991"
            };

            store.AddVehicle(_user.Username, vehicle);

            vehicle = context.Vehicles.First();
            Assert.AreEqual(7000, vehicle.Kilometers);
            Assert.AreEqual(context.Models.First(), vehicle.Model);
            Assert.AreEqual("1991", vehicle.Year);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
Пример #26
0
        public void Change_Email_User_Not_Found()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangeEmail("test", "*****@*****.**");
        }
Пример #27
0
        public void Password_Gets_Encrypted()
        {
            var salt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var password = new byte[] { 5, 6, 7, 8 };
            var encryptor = new Mock<IEncryptor>();
            var context = new MockContext();

            encryptor.Setup(e => e.GetSalt()).Returns(salt);
            encryptor.Setup(e => e.GetPassword(salt, "Password")).Returns(password);

            var userStore = new UserStore(context, encryptor.Object);

            userStore.AddUser(new User{ Username = "******" }, "Password");

            encryptor.Verify(e => e.GetSalt(), Times.Once);
            encryptor.Verify(e => e.GetPassword(salt, "Password"), Times.Once);

            Assert.AreEqual(1, context.Users.Count());
            var user = context.Users.First();
            Assert.AreEqual("test", user.Username);
            Assert.AreEqual(password, user.Password);
            Assert.AreEqual(salt, user.Salt);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }