void UpdateObjective_NewStatus_Success() { // Arrange var bd = "2eee3cf8-329f-4aff-bc56-2ba4851d245c"; Objectives obj = Create(bd); var id = AddObjectiveToDb(new Objective { Name = "Task", UserId = UserIdA, Status = ObjectiveStatus.Waiting }, bd); // Act obj.UpdateObjective(new Objective { Id = id, Name = "Task", UserId = UserIdA, Status = ObjectiveStatus.Cancel }, UserIdA); // Assert CrudDbContextInMemory.Use((context) => { var result = context.Objectives .Where(o => o.Id == id) .SingleOrDefault(); Assert.Equal(ObjectiveStatus.Cancel, result.Status); }, bd); }
public void UpdateObjective_NewName_Success() { //Arrange var bd = "179d257a-33e7-48ba-90e7"; Objectives obj = Create(bd); var id = AddObjectiveToDb(new Objective { Name = "Old task", UserId = UserIdA }, bd); //Act obj.UpdateObjective(new Objective { Id = id, Name = "New task", UserId = UserIdA }, UserIdA); //Assert CrudDbContextInMemory.Use(context => { var objective = context.Objectives.Where(o => o.Id == id).SingleOrDefault(); Assert.NotNull(objective); Assert.Equal("New task", objective.Name); Assert.Equal(UserIdA, objective.UserId); }, bd); }
public static void Use(Action <CrudDbContextInMemory> use, string dbName) { using (var context = new CrudDbContextInMemory(GetOptions(dbName))) { use(context); } }
//Helpers private int AddObjectiveToDb(Objective obj, string dbSignature) { var id = -1; CrudDbContextInMemory.Use(context => { var result = context.Objectives.Add(obj); context.SaveChanges(); id = result.Entity.Id; }, dbSignature); return(id); }
public void RemoveObjective_ById_EmptyGet() { //Arrange var bd = "34890c83-2e02-4602-8457-8c80bd9a0541"; Objectives obj = Create(bd); var id = AddObjectiveToDb(new Objective { Name = "RemoveObjective_ById", UserId = UserIdA }, bd); //Act, Assert obj.RemoveObjective(id, UserIdA); CrudDbContextInMemory.Use(context => { Assert.Empty(context.Objectives.ToList()); }, bd); }
public void SaveObjectve_NewObjective_Success() { //Arrange var bd = "476e0e95-c3f0-4ae4-b312-93a57d7c597f"; Objectives obj = Create(bd); Objective newObj = new Objective { Name = "New One" }; //Act obj.SaveObjective(newObj, UserIdA); //Assert CrudDbContextInMemory.Use(context => { var list = context.Objectives.ToList(); Assert.NotEmpty(list); Assert.Equal("New One", list[0].Name); }, bd); }