コード例 #1
0
        public async Task AggregateDataAsync_ArtistNotFound_ThrowsException()
        {
            // Arrange
            var context = new SutContext();

            context.ArtistService
            .Setup(x => x.GetArtistAsync(It.IsAny <Guid>()))
            .ThrowsAsync(new InvalidOperationException("abc"));

            // Act
            try
            {
                await context.Process.AggregateDataAsync(Guid.NewGuid());

                // Assert
                Assert.Fail("Expected method to throw InvalidOperationException");
            }
            catch (Exception ex)
            {
                // Assert
                var exceptionType = ex.GetType();
                Assert.AreEqual(typeof(InvalidOperationException), exceptionType, $"Expected Exception Type {nameof(InvalidOperationException)} but found {exceptionType}");
                Assert.AreEqual("abc", ex.Message, nameof(ex.Message));
            }
        }
コード例 #2
0
        public async Task AggregateDataAsync_ValidId_ServiceGetsCalledWithCorrectData()
        {
            // Arrange
            var context      = new SutContext();
            var id           = Guid.NewGuid();
            var artistSearch = new ArtistSearch
            {
                Id       = id,
                Name     = "abcdef",
                SortName = "abc",
                Type     = "something",
                Area     = "a"
            };

            context.ArtistService
            .Setup(x => x.GetArtistAsync(id))
            .ReturnsAsync(artistSearch);

            // Act
            var result = await context.Process.AggregateDataAsync(id);

            // Assert
            context.ArtistService.Verify(x => x.GetArtistAsync(id), Times.Once);
            Assert.AreEqual(id, result.ArtistId, nameof(result.ArtistId));
            Assert.AreEqual("abcdef", result.Name, nameof(result.Name));
        }
コード例 #3
0
        public async Task AggregateDataAsync_MixedData_ServiceReturnsCorrectData()
        {
            // Arrange
            var context      = new SutContext();
            var id           = Guid.NewGuid();
            var artistSearch = new ArtistSearch
            {
                Id       = id,
                Name     = "abcdef",
                SortName = "abc",
                Type     = "something",
                Area     = "a"
            };

            // TODO: could refactor and make it data driven
            var works = new[]
            {
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000001"), Title = "1"
                },
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000002"), Title = "2"
                },
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000003"), Title = "3"
                },
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000004"), Title = "4"
                },
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000005"), Title = "5"
                },
                new ArtistWork {
                    Id = new Guid("00000000-0000-0000-0000-000000000006"), Title = "6"
                }
            };

            var expectedResults = new Dictionary <string, (string, int)>()
            {
                { "1", ("a", 1) },
                { "2", ("a a", 2) },