コード例 #1
0
        public void ReturnsICalendarFileWhenProvidingValidSchemaFile()
        {
            IWorkScheduleReader workScheduleReader = Substitute.For <IWorkScheduleReader>();

            workScheduleReader.Read().Returns(new WorkSchedule());

            IWorkScheduleReaderFactory workScheduleReaderFactory = Substitute.For <IWorkScheduleReaderFactory>();

            workScheduleReaderFactory.Create(Arg.Any <Stream>()).Returns(workScheduleReader);

            IWorkScheduleExporter workScheduleExporter = Substitute.For <IWorkScheduleExporter>();

            workScheduleExporter.Export(Arg.Any <WorkSchedule>()).Returns(new byte[0]);

            IWorkScheduleDeliveryService workScheduleDeliveryService = Substitute.For <IWorkScheduleDeliveryService>();

            WorkScheduleExportViewModel model = new WorkScheduleExportViewModel
            {
                SchemaFile = new DummyFormFile()
            };

            controller = new HomeController(workScheduleReaderFactory, workScheduleExporter, workScheduleDeliveryService);

            IActionResult result = controller.Index(model);

            result.ShouldNotBeNull();
            result.ShouldBeOfType <FileContentResult>();
        }
コード例 #2
0
        public void SendsSchemaToEmailWhenProvided()
        {
            IWorkScheduleReader workScheduleReader = Substitute.For <IWorkScheduleReader>();

            workScheduleReader.Read().Returns(new WorkSchedule());

            IWorkScheduleReaderFactory workScheduleReaderFactory = Substitute.For <IWorkScheduleReaderFactory>();

            workScheduleReaderFactory.Create(Arg.Any <Stream>()).Returns(workScheduleReader);

            IWorkScheduleExporter workScheduleExporter = Substitute.For <IWorkScheduleExporter>();

            workScheduleExporter.Export(Arg.Any <WorkSchedule>()).Returns(new byte[0]);

            IWorkScheduleDeliveryService workScheduleDeliveryService = Substitute.For <IWorkScheduleDeliveryService>();

            WorkScheduleExportViewModel model = new WorkScheduleExportViewModel
            {
                Email      = "some-email@localhost",
                SchemaFile = new DummyFormFile()
            };

            controller = new HomeController(workScheduleReaderFactory, workScheduleExporter, workScheduleDeliveryService);

            IActionResult result = controller.Index(model);

            result.ShouldNotBeNull();
            result.ShouldBeOfType <ViewResult>();
            workScheduleDeliveryService.ReceivedWithAnyArgs(1).Deliver(null, null, null);
        }
コード例 #3
0
        public IActionResult Index(WorkScheduleExportViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            IWorkScheduleReader workScheduleReader = workScheduleReaderFactory.Create(model.SchemaFile.OpenReadStream());
            WorkSchedule        workSchedule       = workScheduleReader.Read();

            byte[] exportedSchema = workScheduleExporter.Export(workSchedule);

            if (model.ContainsEmail)
            {
                deliveryService.Deliver(workSchedule, exportedSchema, new WorkScheduleDeliveryOptions {
                    Target = model.Email
                });

                ViewBag.SuccessMessage = "Ditt schema har nu skickats till din e-post";

                return(View());
            }

            return(new FileContentResult(exportedSchema, "text/calendar")
            {
                FileDownloadName = "Arbetsschema.ics"
            });
        }