Skip to content

More logging and fixed default Azure Devops configuration#114

Merged
coenm merged 2 commits intocoenm:mainfrom
Sjoerdsjoerd:feature/MoreLogging
Apr 25, 2024
Merged

More logging and fixed default Azure Devops configuration#114
coenm merged 2 commits intocoenm:mainfrom
Sjoerdsjoerd:feature/MoreLogging

Conversation

@Sjoerdsjoerd
Copy link
Copy Markdown
Contributor

No description provided.

@Sjoerdsjoerd Sjoerdsjoerd changed the title More logging More logging and fixed default Azure Devops configuration Apr 24, 2024
@coenm
Copy link
Copy Markdown
Owner

coenm commented Apr 25, 2024

Replace WebBrowserPackageTest.cs with the following content to fixt the tests

namespace RepoM.Plugin.WebBrowser.Tests;

using System.Collections.Generic;
using System.Threading.Tasks;
using FakeItEasy;
using Microsoft.Extensions.Logging;
using RepoM.Core.Plugin;
using RepoM.Plugin.WebBrowser;
using RepoM.Plugin.WebBrowser.PersistentConfiguration;
using SimpleInjector;
using Xunit;

public class WebBrowserPackageTest
{
    private readonly Container _container;
    private readonly IPackageConfiguration _packageConfiguration;

    public WebBrowserPackageTest()
    {
        _packageConfiguration = A.Fake<IPackageConfiguration>();
        _container = new Container();

        var webBrowserConfigV1 = new WebBrowserConfigV1
            {
                Browsers = new Dictionary<string, string>
                {
                    { "Edge", "msedge.exe" },
                },
                Profiles = new Dictionary<string, ProfileConfig>
                {
                    {
                        "incognito",
                        new ProfileConfig { BrowserName = "Edge", CommandLineArguments = "--incognito", }
                    },
                },
            };
        A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(1 as int?));
        A.CallTo(() => _packageConfiguration.LoadConfigurationAsync<WebBrowserConfigV1>()).ReturnsLazily(() => webBrowserConfigV1);
        A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A<WebBrowserConfigV1>._, 1)).Returns(Task.CompletedTask);
    }

    [Fact]
    public async Task RegisterServices_ShouldBeSuccessful_WhenExternalDependenciesAreRegistered()
    {
        // arrange
        RegisterExternals(_container);
        var sut = new WebBrowserPackage();

        // act
        await sut.RegisterServicesAsync(_container, _packageConfiguration);

        // assert
        // implicit, Verify throws when container is not valid.
        _container.Verify(VerificationOption.VerifyAndDiagnose);
    }

    [Theory]
    [InlineData(null)]
    [InlineData(2)]
    [InlineData(10)]
    public async Task RegisterServices_ShouldPersistNewConfig_WhenVersionIsNotCorrect(int? version)
    {
        // arrange
        RegisterExternals(_container);
        A.CallTo(() => _packageConfiguration.GetConfigurationVersionAsync()).Returns(Task.FromResult(version));
        var sut = new WebBrowserPackage();

        // act
        await sut.RegisterServicesAsync(_container, _packageConfiguration);

        // assert
        A.CallTo(() => _packageConfiguration.PersistConfigurationAsync(A<WebBrowserConfigV1>._, 1)).MustHaveHappenedOnceExactly();

        // implicit, Verify throws when container is not valid.
        _container.Verify(VerificationOption.VerifyAndDiagnose);
    }

    private static void RegisterExternals(Container container)
    {
        container.RegisterSingleton(A.Dummy<ILogger>);
    }
}

@coenm coenm merged commit d834dda into coenm:main Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants