Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Heihokon committed Aug 24, 2023
1 parent 299f1fc commit ea8abc4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Flagship.Tests/FsVisitor/DefaultStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void UpdateContexTest()
defaultStrategy.UpdateContext(newContext);

Assert.AreEqual(visitorDelegate.Context.Count, 6);
Assert.AreEqual(FlagSyncStatus.CONTEXT_UPDATED, visitorDelegate.FlagSyncStatus);

var newContext2 = new Dictionary<string, object>()
{
Expand Down Expand Up @@ -172,6 +173,7 @@ async public Task FetchFlagsTest()
var defaultStrategy = new DefaultStrategy(visitorDelegate);

await defaultStrategy.FetchFlags().ConfigureAwait(false);
Assert.AreEqual(FlagSyncStatus.FLAGS_FETCHED, visitorDelegate.FlagSyncStatus);

Assert.AreEqual(visitorDelegate.Flags.Count, 6);
}
Expand Down Expand Up @@ -475,6 +477,7 @@ public void ExperienceContinuityTest()

Assert.AreEqual(visitorId, visitorDelegate.AnonymousId);
Assert.AreEqual(newVisitorId, visitorDelegate.VisitorId);
Assert.AreEqual(FlagSyncStatus.AUTHENTICATED, visitorDelegate.FlagSyncStatus);

defaultStrategy.Authenticate(null);

Expand Down Expand Up @@ -526,6 +529,8 @@ public void ExperienceContinuityTest()
Assert.IsNull(visitorDelegate.AnonymousId);
Assert.AreEqual(visitorId, visitorDelegate.VisitorId);

Assert.AreEqual(FlagSyncStatus.UNAUTHENTICATED, visitorDelegate.FlagSyncStatus);

defaultStrategy.Unauthenticate();

fsLogManagerMock.Verify(x => x.Error(string.Format(Constants.FLAGSHIP_VISITOR_NOT_AUTHENTICATE, methodName), methodName), Times.Once());
Expand Down
29 changes: 25 additions & 4 deletions Flagship.Tests/FsVisitor/VisitorDelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Flagship.Tests.Data;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Flagship.Logger;

namespace Flagship.FsVisitor.Tests
{
Expand All @@ -28,16 +29,22 @@ public class VisitorDelegateTests

public VisitorDelegateTests()
{
var config = new Flagship.Config.DecisionApiConfig();
configManager = new Mock<Flagship.Config.IConfigManager>();
configManager.SetupGet(x=>x.Config).Returns(config);
var config = new Config.DecisionApiConfig();
configManager = new Mock<Flagship.Config.IConfigManager>()
{
CallBase = true
};
configManager.Object.Config = config;
configManager.SetupGet(x => x.Config).Returns(config);

visitorDelegateMock = new Mock<VisitorDelegate>(new object[] { visitorId, false, context, false, configManager.Object });
visitorDelegateMock.Setup(x=> x.GetStrategy()).CallBase();
defaultStrategy = new Mock<VisitorStrategyAbstract>(visitorDelegateMock.Object);

visitorDelegateMock.Setup<VisitorStrategyAbstract>(x=> x.GetStrategy()).Returns(defaultStrategy.Object);
visitorDelegateMock.Setup(x=> x.GetStrategy()).Returns(defaultStrategy.Object);
visitorDelegateMock.CallBase = true;
visitorDelegateMock.SetupGet(x => x.Config).Returns(config);
visitorDelegateMock.Object.FlagSyncStatus = Enums.FlagSyncStatus.FLAGS_FETCHED;
}


Expand Down Expand Up @@ -70,6 +77,7 @@ public void VisitorDelegateTest()
Assert.IsNotNull(visitor.AnonymousId);
Assert.AreEqual(visitorId, visitor.VisitorId);
Assert.AreEqual(36,visitor.AnonymousId.Length);
Assert.AreEqual(Enums.FlagSyncStatus.CREATED, visitor.FlagSyncStatus);

}

Expand Down Expand Up @@ -154,6 +162,19 @@ public void GetFlagTest4()
Assert.IsFalse(flag.Exists);
}

[TestMethod()]
public void GetFlagTest5()
{
Mock<IFsLogManager> fsLogManagerMock = new Mock<IFsLogManager>();
visitorDelegateMock.Object.Config.LogManager = fsLogManagerMock.Object;
visitorDelegateMock.SetupGet(x => x.Flags).Returns(CampaignsData.GetFlag());
visitorDelegateMock.Object.FlagSyncStatus = Enums.FlagSyncStatus.UNAUTHENTICATED;
var flag = visitorDelegateMock.Object.GetFlag("keyNotExist", new JArray());
Assert.IsNotNull(flag);
Assert.IsFalse(flag.Exists);
fsLogManagerMock.Verify(x=> x.Warning(It.IsAny<string>(), "GET_FLAG"), Times.Once());
}

[TestMethod()]
public void GetFlagMetadataTest()
{
Expand Down

0 comments on commit ea8abc4

Please sign in to comment.