Exemple #1
0
        public void UpdateInvalidUserPermissions()
        {
            UserServiceMocker mocker = new UserServiceMocker();
            UserEntity        entity = new UserEntity();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new UserEntity()
            {
                Email = "*****@*****.**",
                ID    = 1,
                Name  = "testowy"
            });

            mocker.UserResolverServiceMock.Setup(r => r.GetUser())
            .Returns(() => Task.FromResult <UserModel>(new UserModel()
            {
                Email = "*****@*****.**",
                Id    = 2,
                Name  = "testowy"
            }));

            IUserBLService service = mocker.GetService();

            var result = service.Update(0, new UserUpdateModel());

            Assert.Equal("Action forbidden", result.Result.Error.Message);
            Assert.Equal(ErrorStatus.Forbidden, result.Result.Error.Status);
        }
Exemple #2
0
        public void UpdateUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new UserEntity()
            {
                Email = "*****@*****.**",
                ID    = 2,
                Name  = "testowy"
            });

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(
                () => Task.FromResult <UserModel>(new UserModel()
            {
                Email = "*****@*****.**",
                Id    = 2,
                Name  = "testowy"
            }));
            mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.Update(0, new UserUpdateModel());

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #3
0
        public void GetRouteByIdInvalidId()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingleWithDependencies(It.IsAny <int>())).Returns((() => Task.FromResult((UserEntity)null)));

            IUserBLService service = mocker.GetService();

            var result = service.GetById(1);

            Assert.Equal(ErrorStatus.ObjectNotFound, result.Result.Error.Status);
            Assert.Equal("User not found", result.Result.Error.Message);
        }
Exemple #4
0
        public void GetUserByIdUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingleWithDependencies(It.IsAny <int>())).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.GetById(1);

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #5
0
        public void SendConfirmAccountEmailValidResult()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));

            IUserBLService service = mocker.GetService();

            var result = service.SendConfirmAccountEmail();

            Assert.True(result.Result.IsOk);
            Assert.Equal(DateTime.Today.AddDays(30), result.Result.Content.ExpirationDate);
        }
Exemple #6
0
        public void GetAllUsersValidResult()
        {
            var request = new CollectionRequestModel();
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.Search(It.IsAny <SearchQuery <UserEntity> >()))
            .Returns(() => Task.FromResult(new PagingResult <UserEntity>()
            {
                Count   = 2,
                HasNext = false,
                Results = new List <UserEntity>()
                {
                    new UserEntity()
                    {
                        Email  = "*****@*****.**",
                        ID     = 1,
                        Name   = "First",
                        Routes = new List <RouteInfoEntity>()
                        {
                            new RouteInfoEntity()
                            {
                                ID   = 1,
                                Name = "a"
                            }
                        }
                    },
                    new UserEntity()
                    {
                        Email  = "*****@*****.**",
                        ID     = 2,
                        Name   = "Second",
                        Routes = new List <RouteInfoEntity>()
                        {
                            new RouteInfoEntity()
                            {
                                ID   = 2,
                                Name = "b"
                            }
                        }
                    }
                }
            }));

            IUserBLService service = mocker.GetService();

            var result = service.GetAllUsers(request);

            Assert.Equal(true, result.Result.IsOk);
            Assert.Equal(2, result.Result.Content.Count);
            Assert.Equal(false, result.Result.Content.HasNext);
        }
Exemple #7
0
        public void SendConfirmAccountUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.SendConfirmAccountEmail();

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #8
0
        public void GetAllUsersUnhandledException()
        {
            var request = new CollectionRequestModel();
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.Search(It.IsAny <SearchQuery <UserEntity> >())).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.GetAllUsers(request);

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #9
0
        public void ConfirmAccountEmailNullUser()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(null));

            IUserBLService service = mocker.GetService();

            var result = service.ConfirmAccount(new UserAccountConfirmationModel());

            Assert.Equal(ErrorStatus.Forbidden, result.Result.Error.Status);
            Assert.Equal("User is not logged in", result.Result.Error.Message);
        }
Exemple #10
0
        public void SendResetPasswordEmailValidResult()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(new UserEntity()));

            IUserBLService service = mocker.GetService();

            var result = service.SendResetPasswordEmail("*****@*****.**");

            Assert.True(result.Result.IsOk);
            Assert.Equal(DateTime.Today.AddDays(30), result.Result.Content.ExpirationDate);
        }
Exemple #11
0
        public void ResetPasswordlNullUser()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(null));

            IUserBLService service = mocker.GetService();

            var result = service.ResetPassword(new NewPasswordModel());

            Assert.Equal(ErrorStatus.ObjectNotFound, result.Result.Error.Status);
            Assert.Equal("User not found", result.Result.Error.Message);
        }
Exemple #12
0
        public void SendResetPasswordEmailUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(new UserEntity()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.SendResetPasswordEmail("*****@*****.**");

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #13
0
        public void ResetPasswordEmailValidResult()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(new UserEntity()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <SystemCodeEntity, bool> > >()))
            .Returns(() => Task.FromResult <SystemCodeEntity>(new SystemCodeEntity()));

            IUserBLService service = mocker.GetService();

            var result = service.SendResetPasswordEmail("*****@*****.**");

            Assert.True(result.Result.IsOk);
        }
Exemple #14
0
        public void UpdateWrongId()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            UserEntity entity = new UserEntity();

            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => null);

            IUserBLService service = mocker.GetService();

            var result = service.Update(0, new UserUpdateModel());

            Assert.Equal("Id", result.Result.Error.Errors.First().Field);
            Assert.Equal(ErrorStatus.ObjectNotFound, result.Result.Error.Status);
        }
Exemple #15
0
        public void ConfirmAccountEmailValidResult()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <SystemCodeEntity, bool> > >()))
            .Returns(() => Task.FromResult <SystemCodeEntity>(new SystemCodeEntity()));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new UserEntity());

            IUserBLService service = mocker.GetService();

            var result = service.ConfirmAccount(new UserAccountConfirmationModel());

            Assert.True(result.Result.IsOk);
        }
Exemple #16
0
        public void ConfirmAccountInvalidCode()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <SystemCodeEntity, bool> > >()))
            .Returns(() => Task.FromResult <SystemCodeEntity>(null));

            IUserBLService service = mocker.GetService();

            var result = service.ConfirmAccount(new UserAccountConfirmationModel());

            Assert.Equal(ErrorStatus.InvalidModel, result.Result.Error.Status);
            Assert.Equal("Invalid code", result.Result.Error.Message);
        }
Exemple #17
0
        public void CreateUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            UserEntity entity = new UserEntity();

            mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <UserEntity, bool> > >()))
            .Returns(() => Task.FromResult <UserEntity>(null));

            IUserBLService service = mocker.GetService();

            var result = service.Create(new UserCreateModel());

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #18
0
        public void ConfirmAccountUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            mocker.UserResolverServiceMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));
            mocker.SystemCodeRepositoryMock.Setup(r => r.GetSingle(It.IsAny <Expression <Func <SystemCodeEntity, bool> > >()))
            .Returns(() => Task.FromResult <SystemCodeEntity>(new SystemCodeEntity()));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new UserEntity());
            mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.ConfirmAccount(new UserAccountConfirmationModel());

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Exemple #19
0
        public void RemoveUnhandledException()
        {
            UserServiceMocker mocker = new UserServiceMocker();

            UserEntity entity = new UserEntity();

            mocker.RepoMock.Setup(r => r.GetSingleWithDependencies(It.IsAny <int>())).Returns(() => Task.FromResult <UserEntity>(new UserEntity()
            {
                Email  = "*****@*****.**",
                ID     = 2,
                Name   = "testowy",
                Routes = new List <RouteInfoEntity>()
                {
                    new RouteInfoEntity()
                    {
                        ID = 1
                    }
                }
            }));

            mocker.UserResolverServiceMock.Setup(r => r.GetUser())
            .Returns(() => Task.FromResult <UserModel>(new UserModel()
            {
                Email = "*****@*****.**",
                Id    = 2,
                Name  = "testowy"
            }));

            mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));

            IUserBLService service = mocker.GetService();

            var result = service.Remove(new IdModel());

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }