Beispiel #1
0
        public ViewResult GenerateVcfButtonResult()
        {
            var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            GenerateVcfButtonResultViewModel generate = new GenerateVcfButtonResultViewModel();

            var currentUser = manager.FindById(User.Identity.GetUserId());
            var userZip     = currentUser.ZipCode;

            generate.ZipCode = userZip;

            var webClient = new WebClient();

            byte[] result = webClient.DownloadData($"https://congress.api.sunlightfoundation.com/legislators/locate?zip={userZip}");

            var values = "";

            using (var stream = new MemoryStream(result))
                using (var reader = new StreamReader(stream))
                {
                    values = reader.ReadToEnd();
                }

            RepresentativeSearchResult resultObject = JsonConvert.DeserializeObject <RepresentativeSearchResult>(values);

            generate.RepresentativeSearchResult = resultObject;

            return(View(generate));
        }
Beispiel #2
0
        public void DownloadVcfFileResultTestThatFileContentTypeIsVcf()
        {
            HomeController controller = new HomeController();

            RepresentativeSearchResult searchResult = new RepresentativeSearchResult()
            {
                Results = new ReprensentativeContactInfo[3]
                {
                    new ReprensentativeContactInfo()
                    {
                        FirstName = "Bob's",
                        LastName  = "Your Uncle",
                        Phone     = "666-666-6666",
                        OcEmail   = "*****@*****.**"
                    },
                    new ReprensentativeContactInfo()
                    {
                        FirstName = "Annie's",
                        LastName  = "Your Aunt",
                        Phone     = "666-666-6666",
                        OcEmail   = "*****@*****.**"
                    },
                    new ReprensentativeContactInfo()
                    {
                        FirstName = "Satan's",
                        LastName  = "Your Father",
                        Phone     = "666-666-6666",
                        OcEmail   = "*****@*****.**"
                    }
                }
            };

            var file = controller.DownloadVcfFileResult(new ReprensentativeContactInfo()
            {
                FirstName = "Satan's",
                LastName  = "Your Father",
                Phone     = "666-666-6666",
                OcEmail   = "*****@*****.**"
            });

            Assert.IsTrue(file.ContentType == "vcf");
        }