Beispiel #1
0
        private IMEIController CreateController()
        {
            var service    = CreateMockIMEIService();
            var logService = CreateMockLogService();
            var controller = new IMEIController(service.Object, logService.Object);

            return(controller);
        }
Beispiel #2
0
        public void Home()
        {
            var controller = new IMEIController();

            var res = controller.Home();

            var partialView = res as PartialViewResult;

            Assert.NotNull(partialView);
        }
Beispiel #3
0
        private async Task PutIMEIToCallsign(int id, string callsign, string imei, VehicleType?type, ResultType expectedResult = ResultType.Success)
        {
            var logService = CreateMockLogService();
            var service    = CreateMockIMEIService();
            var controller = new IMEIController(service.Object, logService.Object);
            var config     = new Mock <HttpConfiguration>();
            var principal  = MockHelpers.CreateMockPrincipal(TestUsername);

            controller.User          = principal.Object;
            controller.Configuration = config.Object;

            var delta = new Delta <IMEIToCallsign>();

            if (!string.IsNullOrEmpty(imei))
            {
                delta.TrySetPropertyValue("IMEI", imei);
            }
            if (!string.IsNullOrEmpty(callsign))
            {
                delta.TrySetPropertyValue("CallSign", callsign);
            }
            if (type != null)
            {
                delta.TrySetPropertyValue("Type", type);
            }

            var res = await controller.Put(id, delta);

            switch (expectedResult)
            {
            case ResultType.ModelError:
                Assert.IsType <InvalidModelStateResult>(res);
                logService.Verify(l => l.LogIMEIRegistered(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <VehicleType>()), Times.Never);
                break;

            case ResultType.NotFoundError:
                Assert.IsType <NotFoundResult>(res);
                logService.Verify(l => l.LogIMEIRegistered(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <VehicleType>()), Times.Never);
                break;

            case ResultType.Success:
                Assert.IsType <UpdatedODataResult <IMEIToCallsign> >(res);
                service.Verify(i => i.RegisterCallsign(imei, callsign, type));
                logService.Verify(l => l.LogIMEIRegistered(TestUsername, imei, callsign, type ?? VehicleType.Unknown));
                break;
            }
        }
Beispiel #4
0
        private async Task PostIMEIToCallsign(string callsign, string imei, VehicleType type, ResultType expectedResult = ResultType.Success)
        {
            var service    = CreateMockIMEIService();
            var logService = CreateMockLogService();
            var controller = new IMEIController(service.Object, logService.Object);
            var config     = new Mock <HttpConfiguration>();
            var principal  = MockHelpers.CreateMockPrincipal(TestUsername);

            controller.User          = principal.Object;
            controller.Configuration = config.Object;

            var imeiToCallsign = new IMEIToCallsign
            {
                CallSign = callsign,
                IMEI     = imei,
                Type     = type
            };

            MockHelpers.Validate(imeiToCallsign, controller);

            var res = await controller.Post(imeiToCallsign);

            switch (expectedResult)
            {
            case ResultType.ModelError:
                Assert.IsType <InvalidModelStateResult>(res);
                logService.Verify(l => l.LogIMEIRegistered(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <VehicleType>()), Times.Never);
                break;

            case ResultType.Success:
                Assert.IsType <CreatedODataResult <IMEIToCallsign> >(res);
                service.Verify(i => i.RegisterCallsign(imei, callsign, type));
                logService.Verify(l => l.LogIMEIRegistered(TestUsername, imei, callsign, type));
                break;
            }
        }
Beispiel #5
0
        private async Task DeleteCallsign(int id, string imei, bool shouldLog)
        {
            var service    = CreateMockIMEIService();
            var logService = CreateMockLogService();
            var controller = new IMEIController(service.Object, logService.Object);
            var config     = new Mock <HttpConfiguration>();
            var principal  = MockHelpers.CreateMockPrincipal(TestUsername);

            controller.User          = principal.Object;
            controller.Configuration = config.Object;

            var res = await controller.Delete(id);

            var result = res as StatusCodeResult;

            Assert.NotNull(result);

            Assert.Equal(HttpStatusCode.NoContent, result.StatusCode);

            if (shouldLog)
            {
                logService.Verify(l => l.LogIMEIDeleted(TestUsername, imei));
            }
        }