public async void CreateTestAsync() { // Arrange using (var context = new VotingContext(new SqliteProvider().GetDbContextOptions())) { IElectionSaver saver = new ElectionSaver(context); // Act await saver.AddAsync(new Election() { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now, ExpirationDate = DateTime.Now.Add(new TimeSpan(5, 0, 0, 0)) }); await saver.AddAsync(new Election() { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now, ExpirationDate = DateTime.Now.Add(new TimeSpan(5, 0, 0, 0)) }); await saver.AddAsync(new Election() { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now, ExpirationDate = DateTime.Now.Add(new TimeSpan(5, 0, 0, 0)) }); // Assert Assert.Equal(3, context.Elections.Count()); } }
public async void RemoveAllExpiredElectionsTestAsync() { // Arrange using (var context = new VotingContext(new SqliteProvider().GetDbContextOptions())) { IElectionSaver saver = new ElectionSaver(context); await saver.AddAsync(new Election { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now, ExpirationDate = DateTime.Now.Add(new TimeSpan(5, 0, 0, 0)), }); await saver.AddAsync(new Election { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now.Add(new TimeSpan(-15, 0, 0, 0)), ExpirationDate = DateTime.Now.Add(new TimeSpan(-10, 0, 0, 0)), }); // Act : Save an expired election with all the data. SaveCompleteElection(context, saver); // Assert : assert it is saved. Assert.True(context.Ballots.Any()); Assert.True(context.BallotCandidates.Any()); //Act : Remove expired election await saver.RemoveAllExpiredElectionsAsync(); // Assert : Make sure all the ballots and ballot candidates are removed. Assert.True(context.Elections.Count() == 1); Assert.True(!context.Ballots.Any()); Assert.True(!context.BallotCandidates.Any()); } }
public async void RemoveTestAsync() { // Arrange using (var context = new VotingContext(new SqliteProvider().GetDbContextOptions())) { IElectionSaver saver = new ElectionSaver(context); // Act var election1 = new Election { ElectionQr = Guid.NewGuid(), CreatedDate = DateTime.Now, ExpirationDate = DateTime.Now.Add(new TimeSpan(5, 0, 0, 0)), }; election1 = await saver.AddAsync(election1); await saver.RemoveAsync(election1); // Assert Assert.Empty(context.Elections); } }