Example #1
0
        public async Task TestSaveAllElection()
        {
            try
            {
                Guid          newElectionGuid = Guid.NewGuid();
                Guid          newCategoryGuid = Guid.NewGuid();
                List <Ticket> ticketList      = new List <Ticket>()
                {
                    new Ticket()
                    {
                        Id          = Guid.NewGuid(),
                        ElectionId  = newElectionGuid,
                        CategoryId  = newCategoryGuid,
                        Description = "newTicketForCategory",
                        PartyId     = 2
                    }
                };
                List <Category> categoryList = new List <Category>()
                {
                    new Category()
                    {
                        Id             = newCategoryGuid,
                        ElectionId     = newElectionGuid,
                        CategoryTypeId = CategoryTypeEnum.federal,
                        Heading        = "TestNewElectionCategory",
                        Sequence       = 1,
                        JudgePosition  = 2,
                        Tickets        = ticketList,
                    }
                };
                Election election = new Election()
                {
                    Id             = newElectionGuid,
                    Date           = new DateTime(2022, 11, 3).Date,
                    StartDateLocal = new DateTime(2022, 11, 1, 8, 0, 0),
                    EndDateLocal   = new DateTime(2022, 11, 3, 20, 0, 0),
                    Description    = "2022 November Election",
                    Version        = "0.0.0.0",
                    AllowUpdates   = false,
                    CategoryList   = categoryList
                };
                UOW.BeginTransaction();
                Election result = await electionService.SaveAllElection(UOW, election);

                Assert.IsNotNull(election, "Expected election to be saved");
                Assert.IsTrue(election.CategoryList.Count == 1, "Expected Category to be saved.");
                Assert.IsTrue(election.CategoryList[0].Tickets.Count == 1, "Expect one Ticket in category");

                CategoryService categoryService = new CategoryService();
                List <Category> clist           = (await categoryService.GetByElection(Context, newElectionGuid)).ToList();
                Assert.IsTrue(clist.Count == 1, "Expect one Category");
                TicketService ticketService = new TicketService();
                List <Ticket> tlist         = (await ticketService.GetByElection(Context, newElectionGuid)).ToList();
                Assert.IsTrue(tlist.Count == 1, "Expect one Ticket");
                UOW.CloseTransaction();
            }
            catch (Exception ex)
            {
                Assert.IsNull(ex, "Exception Thrown: " + ex.Message);
            }
        }