public async Task ContestStorageCmdInteractor_CreateContestAsync_BadContestObjectParameter() { var contest = new Contest { Name = string.Empty, NumberOfFlyoffRounds = 0, Rounds = new Dictionary <int, Round>(), StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now.AddDays(1), Type = ContestType.F3K, Id = string.Empty }; mockContestRepository.Setup(c => c.CreateAsync(It.IsAny <Contest>())).Returns <Contest>(null); var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); var result = await contestCmdInteractor.CreateContestAsync(contest); // Name is empty Assert.IsTrue(result.IsFaulted); contest.Name = "foo"; contest.NumberOfFlyoffRounds = -1; result = await contestCmdInteractor.CreateContestAsync(contest); // Contest Flyoff Rounds is out of range Assert.IsTrue(result.IsFaulted); contest.NumberOfFlyoffRounds = 0; contest.Rounds = null; result = await contestCmdInteractor.CreateContestAsync(contest); // Contest Rounds is out of range Assert.IsTrue(result.IsFaulted); }
public async Task ContestStorageCmdInteractor_UpdateContestAsync_HappyPath() { var id = "l23l4sdf"; var contestName = "Foo"; var date = DateTimeOffset.Now; var contest = new Contest { Name = contestName, NumberOfFlyoffRounds = 0, Rounds = new Dictionary <int, Round>(), StartDate = date, EndDate = date.AddDays(1), Type = ContestType.F3K, Id = id }; mockContestRepository.Setup(c => c.UpdateAsync(It.IsAny <Contest>())).Returns <Contest>(x => Task.FromResult(new Result <Contest>(contest))); var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); var result = await contestCmdInteractor.UpdateContestAsync(contest); Assert.IsFalse(result.IsFaulted); Assert.AreEqual(id, result.Value.Id); Assert.AreEqual(contestName, result.Value.Name); Assert.AreEqual(contest.NumberOfFlyoffRounds, result.Value.NumberOfFlyoffRounds); Assert.AreEqual(date, result.Value.StartDate); Assert.AreEqual(contest.Rounds.Count, result.Value.Rounds.Count); }
public async Task ContestStorageCmdInteractor_DeleteContestAsync_BadContestObjectParameter() { var contest = new Contest { Name = string.Empty, NumberOfFlyoffRounds = 0, Rounds = new Dictionary <int, Round>(), StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now.AddDays(1), Type = ContestType.F3K, Id = "234wsdfs" }; mockContestRepository.Setup(c => c.DeleteAsync(It.IsAny <string>())).Returns <bool>(x => Task.FromResult(new Result <bool>(false))); var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); var result = await contestCmdInteractor.DeleteContestAsync(contest); // Name is empty Assert.IsTrue(result.IsFaulted); // Contest Flyoff Rounds is out of range contest.Name = "foo"; contest.NumberOfFlyoffRounds = -1; result = await contestCmdInteractor.DeleteContestAsync(contest); Assert.IsTrue(result.IsFaulted); // Contest Rounds is out of range contest.NumberOfFlyoffRounds = 0; contest.Rounds = null; result = await contestCmdInteractor.DeleteContestAsync(contest); // Contest Rounds is out of range Assert.IsTrue(result.IsFaulted); contest.Id = string.Empty; contest.Rounds = new Dictionary <int, Round>(); result = await contestCmdInteractor.DeleteContestAsync(contest); // Contest ID is invalid Assert.IsTrue(result.IsFaulted); }
public async Task ContestStorageCmdInteractor_CreateContestAsync_RepositoryFailure() { var contestName = "Foo"; var date = DateTimeOffset.Now; var contest = new Contest { Name = contestName, NumberOfFlyoffRounds = 0, Rounds = new Dictionary <int, Round>(), StartDate = date, EndDate = date.AddDays(1), Type = ContestType.F3K }; mockContestRepository.Setup(c => c.CreateAsync(It.IsAny <Contest>())).Returns <Contest>(x => Task.FromResult(new Result <Contest>(null))); var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); var result = await contestCmdInteractor.CreateContestAsync(contest); Assert.IsTrue(result.IsFaulted); Assert.IsNull(result.Value); }
/// <summary> /// Initializes a new instance of the <see cref="F3KContestEngine" /> class. /// </summary> /// <param name="taskQueryInteractor">The task query interactor.</param> /// <param name="contestStorageCmdIntr">The contest storage command intr.</param> /// <param name="scoringStorageCmdIntr">The scoring storage command intr.</param> /// <param name="logger">The logger.</param> public F3KContestEngine(TaskQueryInteractor taskQueryInteractor, ContestStorageCmdInteractor contestStorageCmdIntr, ScoringStorageCmdInteractor scoringStorageCmdIntr, ScoringQueryInteractor scoringQueryInteractor, ScoringContestScoreAggInteractor scoringContestScoreAggIntr, FlightMatrixStorageCmdInteractor flightMatrixStorageCmdIntr, FlightMatrixQueryInteractor flightMatrixQueryIntr, PilotQueryInteractor pilotQueryInteractor, ISortingAlgo sortingAlgo, IFlyOffSelectionAlgo flyOffAlgo, ILoggingService logger) : base(contestStorageCmdIntr, scoringStorageCmdIntr) { this.taskQueryInteractor = taskQueryInteractor ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(taskQueryInteractor)} cannot be null"); this.scoringQueryInteractor = scoringQueryInteractor ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(scoringQueryInteractor)} cannot be null"); this.scoringContestScoreAggIntr = scoringContestScoreAggIntr ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(scoringContestScoreAggIntr)} cannot be null"); this.flightMatrixQueryIntr = flightMatrixQueryIntr ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(flightMatrixQueryIntr)} cannot be null"); this.flightMatrixStorageCmdIntr = flightMatrixStorageCmdIntr ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(flightMatrixStorageCmdIntr)} cannot be null"); this.pilotQueryInteractor = pilotQueryInteractor ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(pilotQueryInteractor)} cannot be null"); this.sortingAlgo = sortingAlgo ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(sortingAlgo)} cannot be null"); this.flyOffPilotPicker = flyOffAlgo ?? throw new ArgumentException($"{nameof(F3KContestEngine)}:Ctor - {nameof(flyOffAlgo)} cannot be null"); this.logger = logger ?? throw new ArgumentNullException($"{nameof(F3KContestEngine)}:Ctor - {nameof(logger)} cannot be null"); }
public async Task ContestStorageCmdInteractor_DeleteContestAsync_HappyPath() { var id = "4354rs"; var contestName = "Foo"; var date = DateTimeOffset.Now; var contest = new Contest { Name = contestName, NumberOfFlyoffRounds = 0, Rounds = new Dictionary <int, Round>(), StartDate = date, EndDate = date.AddDays(1), Type = ContestType.F3K, Id = id }; mockContestRepository.Setup(c => c.DeleteAsync(It.IsAny <string>())).Returns <string>(x => Task.FromResult(new Result <bool>(true))); var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); var result = await contestCmdInteractor.DeleteContestAsync(contest); Assert.IsFalse(result.IsFaulted); Assert.IsTrue(result.Value); }
/// <summary> /// Initializes a new instance of the <see cref="ContestController"/> class. /// </summary> /// <param name="contestStorageCmdInteractor">The contest storage command interactor.</param> /// <param name="contestQueryInteractor">The contest query interactor.</param> public ContestController(ContestStorageCmdInteractor contestStorageCmdInteractor, ContestQueryInteractor contestQueryInteractor) { this.contestStorageCmdInteractor = contestStorageCmdInteractor; this.contestQueryInteractor = contestQueryInteractor; }
public async Task ContestStorageCmdInteractor_CreateContestAsync_NullParameters() { var contestCmdInteractor = new ContestStorageCmdInteractor(mockContestRepository.Object, mockLogger.Object); await contestCmdInteractor.CreateContestAsync(null); }
/// <summary> /// Initializes a new instance of the <see cref="ContestEngineBase"/> class. /// </summary> /// <param name="contestStorageCmdInteractor">The contest storage command interactor.</param> /// <param name="scoringStorageCmdInteractor">The scoring storage command interactor.</param> public ContestEngineBase(ContestStorageCmdInteractor contestStorageCmdInteractor, ScoringStorageCmdInteractor scoringStorageCmdInteractor) { this.contestStorageIntr = new Lazy <ContestStorageCmdInteractor>(() => contestStorageCmdInteractor); this.scoringCmdIntr = new Lazy <ScoringStorageCmdInteractor>(() => scoringStorageCmdInteractor); }