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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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)); }
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); }
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); }
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")); }
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); }
public async Task TestCreateMeeting() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); MeetingsService meetingsService = new MeetingsService(context); List <VoteDTO> votes; votes = CreateVotes(); string output = await meetingsService.CreateMeeting("Beer", votes); Assert.Single(context.Meetings.ToList()); Assert.True(context.Meetings.Any(x => x.Id == output)); Meeting meeting = context.Meetings.Where(x => x.Id == output).FirstOrDefault(); Assert.Equal("Beer", meeting.Text); Assert.Equal(3, meeting.Votes.Count()); Assert.Equal("text1", meeting.Votes.ToList()[0].Text); Assert.Equal(1, meeting.Votes.ToList()[0].Yes); Assert.Equal(1, meeting.Votes.ToList()[0].No); Assert.Equal("text2", meeting.Votes.ToList()[1].Text); Assert.Equal(2, meeting.Votes.ToList()[1].Yes); Assert.Equal(2, meeting.Votes.ToList()[1].No); Assert.Equal("text3", meeting.Votes.ToList()[2].Text); Assert.Equal(3, meeting.Votes.ToList()[2].Yes); Assert.Equal(3, meeting.Votes.ToList()[2].No); }
public void TestAllEmptyTable() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); HomeownerSevice homeownerSevice = new HomeownerSevice(context); var list = homeownerSevice.All(); Assert.Empty(list); }
public void TestGetAllApartmentsWithEmptyData() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); ApartmentService apartmentService = new ApartmentService(context); List <Models.ApartmentListDTO> list = apartmentService.GetAllApartments(); Assert.Empty(list); }
public async Task TestCreateWithExistingApartment() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); ApartmentService apartmentService = new ApartmentService(context); await apartmentService.Create(1); await Assert.ThrowsAsync <ACMException>(() => apartmentService.Create(1)); }
public async Task TestCreateIfTheIDIOk() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); ApartmentService apartmentService = new ApartmentService(context); string id = await apartmentService.Create(1); Assert.Equal(1, context.Apartments.Where(x => x.Id == id).FirstOrDefault().Number); }
public async Task TestCreateWithGoodData() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); ApartmentService apartmentService = new ApartmentService(context); await apartmentService.Create(1); Assert.Equal(1, context.Apartments.Count()); }
public void TestGetAllSpendingsEmptyTable() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); SpendingService spendingService = new SpendingService(context); List <SpendingDTO> output = spendingService.GetAllSpendings(); Assert.Empty(output); }
public void TestGetAllCodesEmptyTable() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); CodeService codeService = new CodeService(context); List <Models.CodeDTO> list = codeService.GetAllCodes(); Assert.Empty(list); }
public void TestGetAllMeetingsEmptyTable() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); MeetingsService meetingsService = new MeetingsService(context); List <MeetingsListDTO> output = meetingsService.GetAllMeetings(); Assert.Empty(output); }
public async Task TestBillAllApartmentsEmptyTableAsync() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); BillService billService = new BillService(context); await billService.BillAllApartments("beer", 10); Assert.Empty(context.Bills.ToList()); }
public static int CalcPiResult(int SemestrId, int PiId) { using (var db = new ACMDbContext()) { } return(1); }
public void TestGetOneBillInvalidId() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); BillService billService = new BillService(context); Action act = () => billService.GetOneBill("id"); Assert.Throws <ACMException>(act); }
public void TestGetWallOfShameListEmptyTable() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); BillService billService = new BillService(context); List <WallOfShameElementDTO> list = billService.GetWallOfShameList(); Assert.Empty(list); }
public async Task TestDeleteMeetingInvalidId() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); MeetingsService meetingsService = new MeetingsService(context); string id = await CreateAMeeting(context); await Assert.ThrowsAsync <ACMException>(() => meetingsService.DeleteMeeting(id + "Random string")); }
public async Task TestEditMeetingInvalidId() { ACMDbContext context = ACMDbContextInMemoryFactory.InitializeContext(); MeetingsService meetingsService = new MeetingsService(context); string id = await CreateAMeeting(context); await Assert.ThrowsAsync <ACMException>(() => meetingsService .EditMeeting(id + "Random string", "new text", new List <VoteDTO>())); }