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 TodoDBContext(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 Task_Create()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(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 TodoDBContext(options))
                {
                    var count = context.AcTasks.Where(e => e.Name == "Task test");
                    Assert.Equal(1, count.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task Login_User_Wrong_UserName()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(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 Dictionary <string, object> AddNewTodo(Todo todo)
        {
            int count = userContext.UserList.Where(x => x.Id == todo.user).Count();

            if (todo.Name == null ||
                todo.Name.Length == 0 || count <= 0)
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false },
                    { "message", "Please enter details correctly" }
                });
            }
            bool result = false;

            using (var Context = new TodoDBContext())
            {
                Context.TodoList.Add(todo);
                Context.SaveChanges();
                result = true;
            }
            if (result)
            {
                return(new Dictionary <string, object>()
                {
                    { "success", true }
                });
            }
            return(new Dictionary <string, object>()
            {
                { "success", false },
                { "message", "Failed to add todo" }
            });
        }
        public async Task Login_User()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(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 Category_Update()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(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 TodoDBContext(options))
                {
                    var count = context.AcCategories.Where(e => e.CategoryId == 1 && e.CategoryName == "Task test updated");
                    Assert.Equal(1, count.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task Category_Delete()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(options))
                {
                    var service = new DeleteCategoryCommandHandler(context);
                    var command = new DeleteCategoryCommand();
                    command.Data = new DeleteCategoryRequest
                    {
                        CategoryId = 1,
                        UserName   = "******"
                    };
                    var result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                }

                using (var context = new TodoDBContext(options))
                {
                    var task = context.AcCategories.FirstOrDefault(e => e.CategoryId == 1);
                    Assert.True(task.IsDeleted);
                }
            }
            finally
            {
                connection.Close();
            }
        }
 public Dictionary <string, object> CompleteToDo(int id)
 {
     using (var Context = new TodoDBContext())
     {
         if (Context.TodoList.Where(x => x.Id == id).Count() == 1)
         {
             var todo = Context.TodoList.Where(x => x.Id == id).FirstOrDefault();
             todo.Done = !todo.Done;
             Context.SaveChanges();
             return(new Dictionary <string, object>()
             {
                 { "success", true },
                 { "message", "Todo updated successfully" }
             });
         }
         else
         {
             return(new Dictionary <string, object>()
             {
                 { "success", false },
                 { "message", "No todo exists with that Id" }
             });
         }
     }
 }
        public async Task Create_User()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(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 TodoDBContext(options))
                {
                    var count = context.AcUsers.Where(e => e.FirstName == "test firstname");
                    Assert.Equal(1, count.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #10
0
        public static SqliteConnection GetConnection()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            using (var context = new TodoDBContext(GetMockDBOptions(connection)))
            {
                EnsureCreated(context);
            }
            return(connection);
        }
Beispiel #11
0
 public void AddTodoStep(int todoId, string description)
 {
     //I found out that creating a temporary db context is working better.
     using (TodoDBContext theDB = new TodoDBContext())
     {
         TodoSteps aStep = new TodoSteps()
         {
             Date        = DateTime.Now,
             Description = description,
             TodoId      = todoId
         };
         theDB.TodoSteps.Add(aStep);
         theDB.SaveChanges();
     }
 }
Beispiel #12
0
        public TodoController(TodoDBContext context)
        {
            this._context = context;

            if (_context.TodoItems.Count() == 0)
            {
                var todo = new TodoItem
                {
                    Name            = "Take medicine",
                    TodoDescription = "Take the Valoate CR 500 medicine at night.",
                    IsComplete      = false
                };

                _context.Add(todo);
                _context.SaveChanges();
            }
        }
        public async Task Category_Get()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new TodoDBContext(options))
                {
                    var service = new GetCategoryCommandHandler(context);
                    var command = new GetCategoryCommand();
                    command.Data = new GetCategoryRequest
                    {
                        CategoryId = 1,
                        UserName   = "******"
                    };
                    var result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                    if (result.GetType().IsAssignableTo(typeof(GetCategoryResponse)))
                    {
                        var getCategoryRes = (GetCategoryResponse)result;
                        Assert.NotNull(getCategoryRes.CategoryObj);
                    }

                    command.Data = new GetCategoryRequest
                    {
                        CategoryId = 0,
                        UserName   = "******"
                    };
                    result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                    if (result.GetType().IsAssignableTo(typeof(GetCategoryResponse)))
                    {
                        var getCategoryRes = (GetCategoryResponse)result;
                        Assert.NotNull(getCategoryRes.Categories);
                        Assert.NotEmpty(getCategoryRes.Categories);
                    }
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public Dictionary <string, object> UpdateTodo(Todo updatedTodo)
        {
            int UserExists = userContext.UserList.Where(x => x.Id == updatedTodo.user).Count();
            int TodoExists = Context.TodoList.Where(x => x.Id == updatedTodo.Id).Count();

            if (updatedTodo.Name == null ||
                updatedTodo.Name.Length == 0 || UserExists <= 0 || TodoExists <= 0)
            {
                return(new Dictionary <string, object>()
                {
                    { "success", false },
                    { "message", "Please enter details correctly" }
                });
            }
            using (var Context = new TodoDBContext())
            {
                if (Context.TodoList.Where(x => x.Id == updatedTodo.Id).Count() == 1)
                {
                    var todo = Context.TodoList.Where(x => x.Id == updatedTodo.Id).FirstOrDefault();
                    todo.Name = updatedTodo.Name;
                    Context.SaveChanges();
                    return(new Dictionary <string, object>()
                    {
                        { "success", true },
                        { "message", "Todo updated successfully" }
                    });
                }
                else
                {
                    return(new Dictionary <string, object>()
                    {
                        { "success", false },
                        { "message", "No todo exists with that Id" }
                    });
                }
            }
        }
Beispiel #15
0
 public WarningtimeController(TodoDBContext warningtimeDBContext)
 {
     this.dbContext = warningtimeDBContext;
 }
Beispiel #16
0
        //---------------------------------------------------------------------------------------------------------------------//

        public TodoService(TodoDBContext p_Context)
        {
            this.TodoDBContext = p_Context;
        }
Beispiel #17
0
 public UploadController(TodoDBContext context)
 {
     _context = context;
 }
 public UserLoginCommandHandler(TodoDBContext context, IOptions <AppSettings> appSettings)
 {
     _context     = context;
     _appSettings = appSettings.Value;
 }
 public TodoController(TodoDBContext TodoDBContext)
 {
     this.dbContext = TodoDBContext;
 }
 //public AufgabenVM(IServiceProvider serviceProvider)
 //{
 //   db= serviceProvider.GetRequiredService<TodoDBContext>();
 //}
 public AufgabenVM(TodoDBContext _db)
 {
     db            = _db;
     AufgabenListe = db.Aufgabens.ToList();
 }
Beispiel #21
0
 public TodoService(TodoDBContext c)
 {
     ctx = c;
 }
 public DeleteCategoryCommandHandler(TodoDBContext context)
 {
     _context = context;
 }
 public RealTodoItemService(TodoDBContext context)
 {
     _context = context;
 }
 public TodoListRepository()
 {
     _todoDBContext = new TodoDBContext();
 }
Beispiel #25
0
        //---------------------------------------------------------------------------------------------------------------------//

        public UserService(TodoDBContext p_Context, IConfiguration p_Configuration)
        {
            m_TodoDBContext = p_Context;
            m_SecretKey     = p_Configuration.GetSection("AppSettings:SecretKey").Value;
        }
 public TodoService(TodoDBContext context, IHubContext <TodoHub> todoHub)
 {
     this.dbContext = context;
     _todoHub       = todoHub;
 }
Beispiel #27
0
 public TodoService(TodoDBContext context)
 {
     _context = context;
 }
 public Repository(TodoDBContext context)
 {
     _context = context;
 }
Beispiel #29
0
 public TodoController(TodoDBContext context)
 {
     _context = context;
 }
 public AddCategoryCommandHandler(TodoDBContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }