Beispiel #1
0
        public void RemoveUnhandledException()
        {
            var             mocker = new RouteServiceMocker();
            RouteInfoEntity entity = new RouteInfoEntity();

            mocker.RepoMock.Setup(r => r.Delete(It.IsAny <RouteInfoEntity>())).Callback(() => Console.WriteLine("Unit test delete"));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new RouteInfoEntity()
            {
                ID = 1, Name = "test", UserId = 2
            });
            mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception"));
            mocker.UserResolverMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()
            {
                Email = "*****@*****.**",
                Id    = 2,
                Name  = "testowy"
            }));
            mocker.UserResolverMock.Setup(r => r.IsConfirmed()).Returns(() => Task.FromResult <bool>(true));

            IRouteBLService service = mocker.GetService();

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

            Assert.Equal(ErrorStatus.InternalServer, result.Result.Error.Status);
            Assert.Equal("testexception", result.Result.Error.Message);
        }
Beispiel #2
0
        public async Task <IActionResult> Remove([FromQuery] int id)
        {
            var result = await _routeService.Remove(new IdModel()
            {
                Id = id
            });

            return(WrapResponse(result, HttpStatusCode.OK));
        }
Beispiel #3
0
        public void RemoveNotConfirmed()
        {
            var mocker = new RouteServiceMocker();

            mocker.RepoMock.Setup(r => r.Delete(It.IsAny <RouteInfoEntity>())).Callback(() => Console.WriteLine("Unit test delete"));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new RouteInfoEntity());
            mocker.UserResolverMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()));
            mocker.UserResolverMock.Setup(r => r.IsConfirmed()).Returns(() => Task.FromResult <bool>(false));

            IRouteBLService service = mocker.GetService();

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

            Assert.Equal(ErrorStatus.Forbidden, result.Result.Error.Status);
            Assert.Equal("User is not confirmed", result.Result.Error.Message);
        }
Beispiel #4
0
        public void RemoveValidResult()
        {
            var             mocker = new RouteServiceMocker();
            RouteInfoEntity entity = new RouteInfoEntity();

            mocker.RepoMock.Setup(r => r.Delete(It.IsAny <RouteInfoEntity>())).Callback(() => Console.WriteLine("Unit test delete"));
            mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new RouteInfoEntity()
            {
                ID = 1, Name = "test", UserId = 2
            });
            mocker.UserResolverMock.Setup(r => r.GetUser()).Returns(() => Task.FromResult <UserModel>(new UserModel()
            {
                Email = "*****@*****.**",
                Id    = 2,
                Name  = "testowy"
            }));
            mocker.UserResolverMock.Setup(r => r.IsConfirmed()).Returns(() => Task.FromResult <bool>(true));

            IRouteBLService service = mocker.GetService();

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

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