Beispiel #1
0
        public async Task BillAllApartments(string text, decimal amount)
        {
            IQueryable apartments = context.Apartments;

            foreach (var apartment in apartments)
            {
                await context.Bills.AddAsync(new Bill { Apartment = (Apartment)apartment, Text = text, Amount = amount });
            }
            await context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <bool> DeleteCode(string code)
        {
            RegistrationCode registrationCode = context.RegistrationCodes.Where(x => x.Code == code).FirstOrDefault();

            if (registrationCode == null)
            {
                throw new Utilities.ACMException();
            }
            context.RegistrationCodes.Remove(registrationCode);
            await context.SaveChangesAsync();

            return(true);
        }
        public async Task <string> CreateSpending(SpendingDTO model)
        {
            Spending spending = new Spending
            {
                Amount  = model.Amount,
                Text    = model.Text,
                IsPayed = model.IsPayed
            };
            await context.Spendings.AddAsync(spending);

            await context.SaveChangesAsync();

            return(spending.Id);
        }
        public async Task <bool> AdminDeleteIdea(string id)
        {
            Idea idea = context.Ideas
                        .Where(x => x.Id == id)
                        .FirstOrDefault();

            if (idea == null)
            {
                throw new Utilities.ACMException();
            }
            context.Ideas.Remove(idea);
            await context.SaveChangesAsync();

            return(true);
        }
Beispiel #5
0
        public async Task TestGetAllCodesGoodData()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            RegistrationCode code1 = new RegistrationCode {
                Code = "code1", Apartment = apartment1
            };
            RegistrationCode code2 = new RegistrationCode {
                Code = "code2", Apartment = apartment2
            };
            await context.RegistrationCodes.AddAsync(code1);

            await context.RegistrationCodes.AddAsync(code2);

            await context.SaveChangesAsync();

            var list = codeService.GetAllCodes();

            Assert.Equal(2, list.Count);
            Assert.Equal(1, list[0].ApartmentNumber);
            Assert.Equal("code1", list[0].Code);
            Assert.Equal(2, list[1].ApartmentNumber);
            Assert.Equal("code2", list[1].Code);
        }
Beispiel #6
0
        public async Task TestDeleteBadCode()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            RegistrationCode code1 = new RegistrationCode {
                Code = "code1", Apartment = apartment1
            };
            RegistrationCode code2 = new RegistrationCode {
                Code = "code2", Apartment = apartment2
            };
            await context.RegistrationCodes.AddAsync(code1);

            await context.RegistrationCodes.AddAsync(code2);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(() => codeService.DeleteCode("not a real code"));
        }
Beispiel #7
0
        public async Task TestDeleteCodeGoodData()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            RegistrationCode code1 = new RegistrationCode {
                Code = "code1", Apartment = apartment1
            };
            RegistrationCode code2 = new RegistrationCode {
                Code = "code2", Apartment = apartment2
            };
            await context.RegistrationCodes.AddAsync(code1);

            await context.RegistrationCodes.AddAsync(code2);

            await context.SaveChangesAsync();

            bool output = await codeService.DeleteCode(code1.Code);

            Assert.True(output);
            Assert.Single(context.RegistrationCodes.ToList());
            Assert.Equal("code2", context.RegistrationCodes.ToList()[0].Code);
        }
Beispiel #8
0
        public async Task TestAllGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**", FullName = "gosho"
            };
            Idea idea1 = new Idea {
                Id = "1", User = user, Text = "idea1"
            };
            Idea idea2 = new Idea {
                Id = "2", User = user, Text = "idea2"
            };
            await context.Users.AddAsync(user);

            await context.Ideas.AddAsync(idea1);

            await context.Ideas.AddAsync(idea2);

            await context.SaveChangesAsync();

            var list = homeownerSevice.All();

            Assert.Equal(2, list.Count);
            Assert.Equal("1", list[1].Id);
            Assert.Equal("idea1", list[1].Text);
            Assert.Equal("*****@*****.**", list[1].UserName);
            Assert.Equal("gosho", list[1].Name);
            Assert.Equal("2", list[0].Id);
            Assert.Equal("idea2", list[0].Text);
            Assert.Equal("*****@*****.**", list[0].UserName);
            Assert.Equal("gosho", list[0].Name);
        }
Beispiel #9
0
        public async Task TestEditIdeaGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**", FullName = "gosho"
            };
            Idea idea1 = new Idea {
                Id = "1", User = user, Text = "idea1"
            };
            Idea idea2 = new Idea {
                Id = "2", User = user, Text = "idea2"
            };
            await context.Users.AddAsync(user);

            await context.Ideas.AddAsync(idea1);

            await context.Ideas.AddAsync(idea2);

            await context.SaveChangesAsync();

            bool output = await homeownerSevice.EditIdea(idea1.Id, user.Email, "Edited text");

            Assert.True(output);
            Assert.Equal("Edited text", context.Ideas
                         .Where(x => x.Id == idea1.Id)
                         .FirstOrDefault()
                         .Text);
        }
Beispiel #10
0
        public async Task TestGetIdeaGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**", FullName = "gosho"
            };
            Idea idea1 = new Idea {
                Id = "1", User = user, Text = "idea1"
            };
            Idea idea2 = new Idea {
                Id = "2", User = user, Text = "idea2"
            };
            await context.Users.AddAsync(user);

            await context.Ideas.AddAsync(idea1);

            await context.Ideas.AddAsync(idea2);

            await context.SaveChangesAsync();

            EditIdeaDTO output = homeownerSevice.GetIdea(idea1.Id, user.Email);

            Assert.Equal(idea1.Text, output.Text);
            Assert.Equal(idea1.Id, output.Id);
        }
Beispiel #11
0
        public async Task TestDeleteIdeaGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**", FullName = "gosho"
            };
            Idea idea1 = new Idea {
                Id = "1", User = user, Text = "idea1"
            };
            Idea idea2 = new Idea {
                Id = "2", User = user, Text = "idea2"
            };
            await context.Users.AddAsync(user);

            await context.Ideas.AddAsync(idea1);

            await context.Ideas.AddAsync(idea2);

            await context.SaveChangesAsync();

            bool output = await homeownerSevice.DeleteIdea(idea1.Id, user.Email);

            Assert.True(output);
            Assert.Single(context.Ideas.ToList());
            Assert.True(context.Ideas.Any(x => x.Id == idea2.Id));
        }
Beispiel #12
0
        public async Task TestGetAllApartmentsWithGoodData()
        {
            ACMDbContext     context          = ACMDbContextInMemoryFactory.InitializeContext();
            ApartmentService apartmentService = new ApartmentService(context);
            ACMUser          user             = new ACMUser {
                AppartentNumber = 1
            };
            Apartment apartment1 = new Apartment {
                Number = 1, User = user
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            List <Models.ApartmentListDTO> list = apartmentService.GetAllApartments();

            Assert.Equal(2, list.Count);
            Assert.Equal(1, list[0].Number);
            Assert.Equal(2, list[1].Number);
            Assert.Equal(1, list[0].RegisteredUsersCount);
            Assert.Equal(0, list[1].RegisteredUsersCount);
        }
Beispiel #13
0
 public async Task TestFinancialSummaryEmptyBillsEmptyApartments()
 {
     ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext();
     SummaryService summaryService = new SummaryService(context);
     Spending spending1 = new Spending { Amount = 100, Text = "beer1", IsPayed = true };
     Spending spending2 = new Spending { Amount = 200, Text = "beer2", IsPayed = true };
     Spending spending3 = new Spending { Amount = 300, Text = "beer3", IsPayed = false };
     Spending spending4 = new Spending { Amount = 400, Text = "beer4", IsPayed = false };
     await context.Spendings.AddAsync(spending1);
     await context.Spendings.AddAsync(spending2);
     await context.Spendings.AddAsync(spending3);
     await context.Spendings.AddAsync(spending4);
     await context.SaveChangesAsync();
     FinancialSummaryDTO output = summaryService.FinancialSummary();
     Assert.Empty(output.GoodHomeowners);
     Assert.Empty(output.BadHomeowners);
     Assert.Equal(2, output.PaidSpendings.Count);
     Assert.Equal(100, output.PaidSpendings[1].Amount);
     Assert.Equal("beer1", output.PaidSpendings[1].Text);
     Assert.Equal(200, output.PaidSpendings[0].Amount);
     Assert.Equal("beer2", output.PaidSpendings[0].Text);
     Assert.Equal(2, output.UnpaidSpendings.Count);
     Assert.Equal(300, output.UnpaidSpendings[1].Amount);
     Assert.Equal("beer3", output.UnpaidSpendings[1].Text);
     Assert.Equal(400, output.UnpaidSpendings[0].Amount);
     Assert.Equal("beer4", output.UnpaidSpendings[0].Text);
     Assert.Equal(0, output.Paid);
     Assert.Equal(0, output.ToBePaid);
     Assert.Equal(300, output.Spend);
     Assert.Equal(700, output.ToBeSpend);
     Assert.Equal(-1000, output.CurrentBalance);
 }
Beispiel #14
0
        public async Task TestGetAllSpendingsGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            SpendingService spendingService = new SpendingService(context);
            Spending        spending1       = new Spending
            {
                Amount  = 10,
                Text    = "beer1",
                IsPayed = true
            };
            Spending spending2 = new Spending
            {
                Amount  = 20,
                Text    = "beer2",
                IsPayed = false
            };
            await context.Spendings.AddAsync(spending2);

            await context.Spendings.AddAsync(spending1);

            await context.SaveChangesAsync();

            List <SpendingDTO> output = spendingService.GetAllSpendings();

            Assert.Equal(2, output.Count);
            Assert.True(context.Spendings.Any(x => x.Id == spending1.Id));
            Assert.Equal(20, output[0].Amount);
            Assert.Equal("beer2", output[0].Text);
            Assert.False(output[0].IsPayed);
            Assert.True(context.Spendings.Any(x => x.Id == spending2.Id));
            Assert.Equal(10, output[1].Amount);
            Assert.Equal("beer1", output[1].Text);
            Assert.True(output[1].IsPayed);
        }
Beispiel #15
0
        public async Task TestEditBillWithInvalidId()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            BillService  billService = new BillService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            Bill bill = new Bill {
                Amount = 10, Apartment = apartment1, Text = "beer"
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            await context.Bills.AddAsync(bill);

            await context.SaveChangesAsync();

            BillsDTO model = new BillsDTO
            {
                Id        = bill.Id + "Random string",
                Amount    = "100",
                Apartment = 2,
                Ispayed   = true,
                Text      = "Alot of beer"
            };
            await Assert.ThrowsAsync <ACMException>(() => billService.EditBill(model));
        }
Beispiel #16
0
        public async Task TestGetOneBillGoodData()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            BillService  billService = new BillService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Bill bill = new Bill {
                Amount = 10, Apartment = apartment1, Text = "beer"
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Bills.AddAsync(bill);

            await context.SaveChangesAsync();

            BillsDTO newBill = billService.GetOneBill(bill.Id);

            Assert.Equal(bill.Id, newBill.Id);
            Assert.Equal(bill.Apartment.Number, newBill.Apartment);
            Assert.Equal(bill.Amount.ToString(), newBill.Amount);
            Assert.Equal(bill.IssuedOn, newBill.Date);
            Assert.Equal(bill.Text, newBill.Text);
            Assert.False(newBill.Ispayed);
        }
Beispiel #17
0
        public async Task TestPayBillGoodData()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            BillService  billService = new BillService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Bill bill1 = new Bill
            {
                Amount    = 10,
                Apartment = apartment1,
                Text      = "beer",
                IsPayed   = false,
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Bills.AddAsync(bill1);

            await context.SaveChangesAsync();

            bool output = await billService.PayBill(bill1.Id);

            Assert.True(output);
            Assert.True(bill1.IsPayed);
        }
Beispiel #18
0
        public async Task TestGetIdeaInvalidId()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**", FullName = "gosho"
            };
            Idea idea1 = new Idea {
                Id = "1", User = user, Text = "idea1"
            };
            Idea idea2 = new Idea {
                Id = "2", User = user, Text = "idea2"
            };
            await context.Users.AddAsync(user);

            await context.Ideas.AddAsync(idea1);

            await context.Ideas.AddAsync(idea2);

            await context.SaveChangesAsync();

            Action act = () => homeownerSevice
                         .GetIdea(idea1.Id + "Random string", user.Email);

            Assert.Throws <ACMException>(act);
        }
Beispiel #19
0
        public async Task TestEditSpedningGoodData()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            SpendingService spendingService = new SpendingService(context);
            Spending        spending        = new Spending
            {
                Amount  = 10,
                Text    = "beer",
                IsPayed = true
            };
            await context.Spendings.AddAsync(spending);

            await context.SaveChangesAsync();

            SpendingDTO model = new SpendingDTO
            {
                Amount  = 100,
                Text    = "alot of beer",
                IsPayed = false,
                Id      = spending.Id
            };
            bool output = await spendingService.EditSpending(model);

            Assert.True(output);
            Assert.Equal(100, context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().Amount);
            Assert.Equal("alot of beer", context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().Text);
            Assert.False(context.Spendings.Where(x => x.Id == spending.Id).FirstOrDefault().IsPayed);
        }
Beispiel #20
0
        public async Task <string> AddNewIp(string name, string ip)
        {
            ACMUser user = context.Users.Where(x => x.UserName == name).FirstOrDefault();

            if (user == null)
            {
                throw new ACMException();
            }
            IP newIp = new IP {
                User = user, IpString = ip
            };
            await context.IPs.AddAsync(newIp);

            await context.SaveChangesAsync();

            return(newIp.Id);
        }
Beispiel #21
0
 public async Task TestFinancialSummaryGoodData()
 {
     ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext();
     SummaryService summaryService = new SummaryService(context);
     Apartment apartment1 = new Apartment { Number = 1 };
     Apartment apartment2 = new Apartment { Number = 2 };
     Apartment apartment3 = new Apartment { Number = 3 };
     Apartment apartment4 = new Apartment { Number = 4 };
     Bill bill1 = new Bill { Amount = 10, Apartment = apartment1, IsPayed = true };
     Bill bill2 = new Bill { Amount = 20, Apartment = apartment2, IsPayed = true };
     Bill bill3 = new Bill { Amount = 30, Apartment = apartment3, IsPayed = false };
     Bill bill4 = new Bill { Amount = 40, Apartment = apartment4, IsPayed = false };
     Spending spending1 = new Spending{Amount = 100,Text = "beer1",IsPayed = true};
     Spending spending2 = new Spending{Amount = 200,Text = "beer2",IsPayed = true};
     Spending spending3 = new Spending{Amount = 300,Text = "beer3",IsPayed = false};
     Spending spending4 = new Spending{Amount = 400,Text = "beer4",IsPayed = false};
      await context.Apartments.AddAsync(apartment1);
      await context.Apartments.AddAsync(apartment2);
      await context.Apartments.AddAsync(apartment3);
      await context.Apartments.AddAsync(apartment4);
      await context.Bills.AddAsync(bill1);
      await context.Bills.AddAsync(bill2);
      await context.Bills.AddAsync(bill3);
      await context.Bills.AddAsync(bill4);
      await context.Spendings.AddAsync(spending1);
      await context.Spendings.AddAsync(spending2);
      await context.Spendings.AddAsync(spending3);
      await context.Spendings.AddAsync(spending4);
     await context.SaveChangesAsync();
     FinancialSummaryDTO output = summaryService.FinancialSummary();
     Assert.Equal(2, output.GoodHomeowners.Count);
     Assert.Equal(1, output.GoodHomeowners[0].ApartmentNumber);
     Assert.Equal(0, output.GoodHomeowners[0].Amount);
     Assert.Equal(2, output.GoodHomeowners[1].ApartmentNumber);
     Assert.Equal(0, output.GoodHomeowners[1].Amount);
     Assert.Equal(2, output.BadHomeowners.Count);
     Assert.Equal(3, output.BadHomeowners[1].ApartmentNumber);
     Assert.Equal(30, output.BadHomeowners[1].Amount);
     Assert.Equal(4, output.BadHomeowners[0].ApartmentNumber);
     Assert.Equal(40, output.BadHomeowners[0].Amount);
     Assert.Equal(2, output.PaidSpendings.Count);
     Assert.Equal(100, output.PaidSpendings[1].Amount);
     Assert.Equal("beer1", output.PaidSpendings[1].Text);
     Assert.Equal(200, output.PaidSpendings[0].Amount);
     Assert.Equal("beer2", output.PaidSpendings[0].Text);
     Assert.Equal(2, output.UnpaidSpendings.Count);
     Assert.Equal(300, output.UnpaidSpendings[1].Amount);
     Assert.Equal("beer3", output.UnpaidSpendings[1].Text);
     Assert.Equal(400, output.UnpaidSpendings[0].Amount);
     Assert.Equal("beer4", output.UnpaidSpendings[0].Text);
     Assert.Equal(30, output.Paid);
     Assert.Equal(70, output.ToBePaid);
     Assert.Equal(300, output.Spend);
     Assert.Equal(700, output.ToBeSpend);
     Assert.Equal(-900, output.CurrentBalance);
 }
Beispiel #22
0
        public async Task TestCreateARegistrationCodeInvalidApartmentNumber()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            await context.Apartments.AddAsync(apartment1);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(() => codeService.CreateARegistrationCode("0"));
        }
Beispiel #23
0
        public async Task TestAdminDeleteIdeaInvalidId()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            Idea            idea            = new Idea {
                Id = "1"
            };
            await context.AddAsync(idea);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(() => homeownerSevice.AdminDeleteIdea("2"));
        }
Beispiel #24
0
        public async Task TestGetAllBills()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            BillService  billService = new BillService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            Bill bill1 = new Bill
            {
                Amount    = 10,
                Apartment = apartment1,
                Text      = "beer",
                IsPayed   = true,
            };
            Bill bill2 = new Bill
            {
                Amount    = 1,
                Apartment = apartment2,
                Text      = "beer2",
                IsPayed   = false,
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            await context.Bills.AddAsync(bill1);

            await context.Bills.AddAsync(bill2);

            await context.SaveChangesAsync();

            List <BillsDTO> list = billService.GetAllBills();

            Assert.Equal(2, list.Count);
            Assert.Equal(bill2.Id, list[0].Id);
            Assert.Equal(bill2.Apartment.Number, list[0].Apartment);
            Assert.Equal(bill2.Amount.ToString(), list[0].Amount);
            Assert.Equal(bill2.IssuedOn, list[0].Date);
            Assert.Equal(bill2.Text, list[0].Text);
            Assert.True(list[1].Ispayed);
            Assert.Equal(bill1.Id, list[1].Id);
            Assert.Equal(bill1.Apartment.Number, list[1].Apartment);
            Assert.Equal(bill1.Amount.ToString(), list[1].Amount);
            Assert.Equal(bill1.IssuedOn, list[1].Date);
            Assert.Equal(bill1.Text, list[1].Text);
            Assert.False(list[0].Ispayed);
        }
Beispiel #25
0
        public async Task TestGenerateCodeInvalidUser()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            UserService  userService = new UserService(context);
            ACMUser      user        = new ACMUser {
                UserName = "******"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(()
                                                    => userService.GenerateCode("Not gosho"));
        }
Beispiel #26
0
        public async Task TestCreateInvalidUser()
        {
            ACMDbContext context   = ACMDbContextInMemoryFactory.InitializeContext();
            IPService    iPService = new IPService(context);
            ACMUser      user      = new ACMUser {
                UserName = "******", FullName = "gosho"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            IpDTO model = new IpDTO(null, "123.123.123...");
            await Assert.ThrowsAsync <ACMException>(() => iPService.Create(model));
        }
Beispiel #27
0
        public async Task TestCreateInvalidUser()
        {
            ACMDbContext    context         = ACMDbContextInMemoryFactory.InitializeContext();
            HomeownerSevice homeownerSevice = new HomeownerSevice(context);
            ACMUser         user            = new ACMUser {
                Email = "*****@*****.**"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(()
                                                    => homeownerSevice.Create("beer", "NOT [email protected]"));
        }
Beispiel #28
0
        public async Task TestGetApartmentNumberInvalidUser()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            UserService  userService = new UserService(context);
            ACMUser      user        = new ACMUser {
                Email = "gosho", AppartentNumber = 1
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            Action act = () => userService.GetApartmentNumber("Not gosho");

            Assert.Throws <ACMException>(act);
        }
Beispiel #29
0
        public async Task TestIsCodeValidInvalidCode()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            UserService  userService = new UserService(context);
            ACMUser      user        = new ACMUser {
                UserName = "******", ExpectedCode = "1"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            bool output = userService.IsCodeValid("2", "gosho");

            Assert.False(output);
        }
Beispiel #30
0
        public async Task <string> CreateMeeting(string text, List <VoteDTO> votes)
        {
            Meeting meeting = new Meeting();

            meeting.Text = text;
            Vote vote;

            for (int i = 0; i < votes.Count; i++)
            {
                vote = new Vote
                {
                    Text    = votes[i].Text,
                    Yes     = votes[i].Yes,
                    No      = votes[i].No,
                    Meeting = meeting
                };
                await context.Votes.AddAsync(vote);
            }
            await context.Meetings.AddAsync(meeting);

            await context.SaveChangesAsync();

            return(meeting.Id);
        }