Ejemplo n.º 1
0
        private static TextResourceService GetServiceForTest(Mock <IAltinnStorageTextResourceClient> storageClientMock = null)
        {
            storageClientMock ??= new Mock <IAltinnStorageTextResourceClient>();

            TextResourceService service = new TextResourceService(
                new IGiteaMock(),
                new Mock <ILogger <TextResourceService> >().Object,
                storageClientMock.Object);

            return(service);
        }
Ejemplo n.º 2
0
        public async Task UpdateTextResourcesAsync_InvalidTextResource_NoTextResourceIsCreatedInStorage()
        {
            // Arrange
            HttpContext httpContext = GetHttpContextForTestUser("testUser");
            Mock <IAltinnStorageTextResourceClient> storageClientMock = new Mock <IAltinnStorageTextResourceClient>();

            storageClientMock.Setup(s => s.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <EnvironmentModel>()))
            .Returns(Task.FromResult((StorageInterface.TextResource)null));

            TextResourceService sut = GetServiceForTest(storageClientMock);

            // Act
            await sut.UpdateTextResourcesAsync("ttd", "apps-test", "a69255710e6f1d1c59bef004dd36fff0c5dfd236", null);

            // Assert
            storageClientMock.Verify(
                s =>
                s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <StorageInterface.TextResource>(), It.IsAny <EnvironmentModel>()),
                Times.Never);
        }
Ejemplo n.º 3
0
        public async Task UpdateTextResourcesAsync_InvalidFileName_SingleTextResourcesAreCreatedInStorage()
        {
            // Arrange
            HttpContext httpContext = GetHttpContextForTestUser("testUser");
            Mock <IAltinnStorageTextResourceClient> storageClientMock = new Mock <IAltinnStorageTextResourceClient>();

            storageClientMock.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <StorageInterface.TextResource>(), It.IsAny <EnvironmentModel>()))
            .Returns(Task.CompletedTask);
            storageClientMock.Setup(s => s.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <EnvironmentModel>()))
            .Returns(Task.FromResult((StorageInterface.TextResource)null));

            TextResourceService sut = GetServiceForTest(storageClientMock);

            // Act
            await sut.UpdateTextResourcesAsync("ttd", "apps-test", "5e651c2b784571e481c90fbf26325ce336b634b8", null);

            // Assert
            storageClientMock.Verify(
                s =>
                s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <StorageInterface.TextResource>(), It.IsAny <EnvironmentModel>()),
                Times.Once);
        }
Ejemplo n.º 4
0
        public async Task UpdateTextResourcesAsync_AllValidFiles_TwoTextResourcesAreCreatedInStorage()
        {
            // Arrange
            HttpContext httpContext = GetHttpContextForTestUser("testUser");
            Mock <IAltinnStorageTextResourceClient> storageClientMock = new Mock <IAltinnStorageTextResourceClient>();

            storageClientMock.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <StorageInterface.TextResource>(), It.IsAny <EnvironmentModel>()))
            .Returns(Task.CompletedTask);
            storageClientMock.Setup(s => s.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <EnvironmentModel>()))
            .Returns(Task.FromResult((StorageInterface.TextResource)null));

            TextResourceService sut = GetServiceForTest(storageClientMock);

            // Act
            await sut.UpdateTextResourcesAsync("ttd", "apps-test", "3e1099738e0d15490390a01c74b2abc16282d85f", null);

            // Assert
            storageClientMock.Verify(
                s =>
                s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <StorageInterface.TextResource>(), It.IsAny <EnvironmentModel>()),
                Times.Exactly(2));
        }