Esempio n. 1
0
        public void PassingUnAuthorisableGroupIDToControllerThrowsUnauthorizedResult()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);


            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);

            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(s => s.IsAuthorized(It.IsNotIn <string>(new List <string>()
            {
                "426"
            }))).Returns(false);

            var controller = new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);


            Task <IHttpActionResult> actionResult = controller.SetDataAsync("123", models);

            Assert.IsInstanceOfType(actionResult.Result, typeof(UnauthorizedResult));
        }
Esempio n. 2
0
        public void PassingNonNumericGroupIDToControllerResultsBadRequest()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);


            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);

            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);


            var controller = new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);
            Task <IHttpActionResult> actionResult = controller.SetDataAsync("abc", null);

            Assert.IsInstanceOfType(actionResult.Result, typeof(BadRequestResult));
        }
Esempio n. 3
0
        public void PassingAuthorisableGroupIDToControllerReturnsOkResult()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);
            var qRepo = new Mock <IQueueRepository>(MockBehavior.Strict);

            repository.Setup(r => r.SetDataAsync(It.IsAny <UserContext>(),
                                                 It.IsAny <List <MassTerminationModelSerialized> >()))
            .ReturnsAsync(new List <DataloadBatch>()
            {
                new DataloadBatch {
                    BatchID = Guid.NewGuid(), JobID = Guid.NewGuid()
                }
            });

            qRepo.Setup(r => r.PushDataAsync(It.IsAny <IEnumerable <DataloadBatch> >()))
            .ReturnsAsync(true);


            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);
            dataFactory.Setup(d => d.GetQueueRepository()).Returns(qRepo.Object);


            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(s => s.IsAuthorized(It.IsIn <string>(new List <string>()
            {
                "426"
            }))).Returns(true);

            var controller = new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);


            Task <IHttpActionResult> actionResult = controller.SetDataAsync("426", models);

            Assert.IsInstanceOfType(actionResult.Result, typeof(OkResult));
        }
Esempio n. 4
0
        public void SetDataAsyncWithoutSaveFromRepositoryReturnsNotFoundResult()
        {
            //Mock the repository
            var repository =
                new Mock <IStagingRepository <MassTerminationModelSerialized> >(MockBehavior.Strict);
            var qRepo = new Mock <IQueueRepository>(MockBehavior.Strict);

            repository.Setup(r => r.SetDataAsync(It.IsAny <UserContext>(),
                                                 It.IsAny <List <MassTerminationModelSerialized> >()))
            .ReturnsAsync(new List <DataloadBatch>());

            //Mock data factory
            var dataFactory =
                new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetMassTerminateRepository()).Returns(repository.Object);
            dataFactory.Setup(d => d.GetQueueRepository()).Returns(qRepo.Object);

            //Mapping factory
            IMappingFactory mapFactory = new MappingFactory();

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(s => s.IsAuthorized(It.IsIn <string>(new List <string>()
            {
                "426"
            }))).Returns(true);

            var controller = new MassTerminateController(dataFactory.Object, authorization.Object, mapFactory);


            Task <IHttpActionResult> actionResult = controller.SetDataAsync("426", models);

            Assert.IsInstanceOfType(actionResult.Result, typeof(NotFoundResult));
        }