Пример #1
0
        public void CreateAttemptAsync_GivenInvalidGoalId_ShouldRaiseException()
        {
            // Arrange.
            var attemptDb      = Substitute.For <IGoalAttemptDb>();
            var goalStore      = Substitute.For <IGoalStore>();
            var dateTimeSource = Substitute.For <IDateTimeSource>();
            var testObject     = new GoalAttemptStore(attemptDb, goalStore, dateTimeSource);

            // Act & assert.
            Assert.That(
                () => testObject.CreateAttemptAsync(0),
                Throws
                .TypeOf <ArgumentException>()
                .With.Message.EqualTo("Goal not found with id 0."));
        }
Пример #2
0
        public async Task CreateAttemptAsync_GivenValidAttempt_ShouldAddToDb()
        {
            // Arrange.
            var attemptDb      = Substitute.For <IGoalAttemptDb>();
            var goalStore      = Substitute.For <IGoalStore>();
            var dateTimeSource = Substitute.For <IDateTimeSource>();
            var testObject     = new GoalAttemptStore(attemptDb, goalStore, dateTimeSource);

            goalStore.GetGoalAsync(123).Returns(new Goal());
            dateTimeSource.Now.Returns(DateTime.Now);

            // Act.
            GoalAttempt attempt = await testObject.CreateAttemptAsync(123);

            // Assert.
            attemptDb.Received(1).AddAttempt(Arg.Any <GoalAttempt>());

            await attemptDb.Received(1).SaveAsync();

            Assert.AreEqual(123, attempt.GoalId);
            Assert.AreEqual(dateTimeSource.Now, attempt.Timestamp);
        }