public async Task Task_Delete() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new DeleteTodoCommandHandler(context); var command = new DeleteTodoCommand(); command.Data = new DeleteTodoRequest { TodoId = 2, UserName = "******" }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var task = context.AcTasks.FirstOrDefault(e => e.TaskId == 2); Assert.True(task.IsDeleted); } } finally { connection.Close(); } }
public async Task Login_User_Wrong_UserName() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { TestHelper.EnsureCreated(context); var service = new UserLoginCommandHandler(context, TestHelper.GetAppSettings()); var command = new UserLoginCommand(); command.Data = new UserLoginRequest { Password = "******", UserName = "******" }; var result = await service.Execute(command); Assert.False(result.Result.IsSuccess); Assert.Equal("Incorrect username or password", result.Result.Error.ErrorText); } } finally { connection.Close(); } }
public async Task Task_Create() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new AddTodoCommandHandler(context, TestHelper.GetMapperInstance()); var command = new AddTodoCommand(); command.Data = new AddTodoRequest { UserName = "******", Name = "Task test", CategoryId = 1, TaskPriority = TaskPriority.P1, TaskStatus = Models.EntityModels.TaskStatus.Todo }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var count = context.AcTasks.Where(e => e.Name == "Task test"); Assert.Equal(1, count.Count()); } } finally { connection.Close(); } }
public async Task Create_User_Email_Already_Exists() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { // Run the test against one instance of the context using (var context = new AppcentTodoContext(options)) { TestHelper.EnsureCreated(context); var service = new RegisterUserCommandHandler(context, TestHelper.GetMapperInstance()); var command = new RegisterUserCommand(); command.Data = new RegisterUserRequest { Email = "*****@*****.**", FirstName = "test firstname", LastName = "test lastname", Password = "******", UserName = "******" }; var result = await service.Execute(command); Assert.False(result.Result.IsSuccess); Assert.Equal("Email is already in use", result.Result.Error.ErrorText); } } finally { connection.Close(); } }
public async Task Login_User() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { TestHelper.EnsureCreated(context); var service = new UserLoginCommandHandler(context, TestHelper.GetAppSettings()); var command = new UserLoginCommand(); command.Data = new UserLoginRequest { Password = "******", UserName = "******" }; var result = await service.Execute(command); if (result.GetType().IsAssignableTo(typeof(UserLoginResponse))) { var res = (UserLoginResponse)result; Assert.NotEqual <string>(res.Token, string.Empty); } Assert.True(result.Result.IsSuccess); } } finally { connection.Close(); } }
public async Task Create_User() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new RegisterUserCommandHandler(context, TestHelper.GetMapperInstance()); var command = new RegisterUserCommand(); command.Data = new RegisterUserRequest { Email = "test email", FirstName = "test firstname", LastName = "test lastname", Password = "******", UserName = "******" }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var count = context.AcUsers.Where(e => e.FirstName == "test firstname"); Assert.Equal(1, count.Count()); } } finally { connection.Close(); } }
public async Task Category_Update() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new UpdateCategoryCommandHandler(context, TestHelper.GetMapperInstance()); var command = new UpdateCategoryCommand(); command.Data = new UpdateCategoryRequest { CategoryId = 1, UserName = "******", Name = "Task test updated" }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); } using (var context = new AppcentTodoContext(options)) { var count = context.AcCategories.Where(e => e.CategoryId == 1 && e.CategoryName == "Task test updated"); Assert.Equal(1, count.Count()); } } finally { connection.Close(); } }
public static SqliteConnection GetConnection() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); using (var context = new AppcentTodoContext(GetMockDBOptions(connection))) { EnsureCreated(context); } return(connection); }
public async Task Task_Get() { var connection = TestHelper.GetConnection(); var options = TestHelper.GetMockDBOptions(connection); try { using (var context = new AppcentTodoContext(options)) { var service = new GetTodoCommandHandler(context); var command = new GetTodoCommand(); command.Data = new GetTodoRequest { TaskId = 1, UserName = "******" }; var result = await service.Execute(command); Assert.True(result.Result.IsSuccess); if (result.GetType().IsAssignableTo(typeof(GetTodoResponse))) { var getTodoRes = (GetTodoResponse)result; Assert.NotNull(getTodoRes.TodoObj); } command.Data = new GetTodoRequest { TaskId = 0, UserName = "******" }; result = await service.Execute(command); Assert.True(result.Result.IsSuccess); if (result.GetType().IsAssignableTo(typeof(GetTodoResponse))) { var getTodoRes = (GetTodoResponse)result; Assert.NotNull(getTodoRes.TodoList); Assert.NotEmpty(getTodoRes.TodoList); } } } finally { connection.Close(); } }
public AddTodoCommandHandler(AppcentTodoContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public RegisterUserCommandHandler(AppcentTodoContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public DeleteTodoCommandHandler(AppcentTodoContext context) { _context = context; }
public GetCategoryCommandHandler(AppcentTodoContext context) { _context = context; }
public UserLoginCommandHandler(AppcentTodoContext context, IOptions <AppSettings> appSettings) { _context = context; _appSettings = appSettings.Value; }
public static void EnsureCreated(AppcentTodoContext context) { if (context.Database.EnsureCreated()) { var user = new AcUser { Email = "*****@*****.**", FirstName = "Burak", LastName = "Portakal", Password = "******",//testtest UserName = "******", Salt = "tOoByYVHjUQ4Ue+SWZPmEQ==", CreateDate = DateTime.Now }; context.AcUsers.Add(user); context.AcTaskStatuses.Add(new AcTaskStatus { Status = "Todo" }); context.AcTaskStatuses.Add(new AcTaskStatus { Status = "InProgress" }); context.AcTaskStatuses.Add(new AcTaskStatus { Status = "Completed" }); context.AcTaskPriorities.Add(new AcTaskPriority { Priority = "P1" }); context.AcTaskPriorities.Add(new AcTaskPriority { Priority = "P2" }); context.AcTaskPriorities.Add(new AcTaskPriority { Priority = "P3" }); context.AcCategories.Add(new AcCategory { CategoryName = "Project", User = user }); context.AcTasks.Add(new AcTask { Name = "Test task", CategoryId = 1, Status = 1, TaskPriorityId = 1, User = user, IsDeleted = false, CreateDate = DateTime.Now }); context.AcTasks.Add(new AcTask { Name = "Test task 2", CategoryId = 1, Status = 1, TaskPriorityId = 1, User = user, IsDeleted = false, CreateDate = DateTime.Now }); context.SaveChanges(); } }
public UpdateCategoryCommandHandler(AppcentTodoContext context, IMapper mapper) { _context = context; _mapper = mapper; }