Esempio n. 1
0
        public async Task GetAllAsync_WhenGoalsCached_ShouldReturnCorrectly(
            List <Goal> goals,
            GoalQueryWithCache sut)
        {
            // Arrange
            var allGoalsKey = "All-Goals";

            sut.Cache.GetAsync <List <Goal> >(Arg.Is(allGoalsKey))
            .Returns(goals);

            // Act
            var result = await sut.GetAllAsync();

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <List <Goal> >();
            result.Should().BeEquivalentTo(goals);
            await sut.Cache.Received(1).GetAsync <List <Goal> >(Arg.Is(allGoalsKey));

            await sut.InnerGoalQuery.DidNotReceive().GetAllAsync();

            await sut.Cache.DidNotReceive().SetAsync <List <Goal> >(Arg.Any <string>(), Arg.Any <List <Goal> >());
        }
Esempio n. 2
0
        public async Task GetAsync_WhenGoalNotCached_ShouldCallMethodsCorrectly(
            Guid goalId,
            Goal goal,
            GoalQueryWithCache sut)
        {
            // Arrange
            var goalKey = $"{typeof(Goal).Name}-{goalId}";

            sut.Cache.GetAsync <Goal>(Arg.Any <string>()).ReturnsNull();
            sut.InnerGoalQuery.GetAsync(Arg.Is(goalId)).Returns(goal);

            // Act
            var result = await sut.GetAsync(goalId);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <Goal>();
            result.Should().BeEquivalentTo(goal);
            await sut.Cache.Received(1).GetAsync <Goal>(Arg.Is(goalKey));

            await sut.InnerGoalQuery.Received(1).GetAsync(Arg.Is(goalId));

            await sut.Cache.Received(1).SetAsync <Goal>(Arg.Is(goalKey), Arg.Is(goal));
        }