public async Task WhenNoCompetitor_DrawCompetition_NoWinner() { var utcNow = DateTimeOffset.UtcNow; var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", Locale = "en-US", OffsetHours = 8, Gift = "gift name", IsCompleted = false, Competitors = new List <Competitor>(), WinnerCount = 1, WinnerAadObjectIds = new List <string>() }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); arrangement.SetUtcNow(utcNow); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.PostAsync($"competitions/{competition.Id}/draw", new StringContent(string.Empty)); response.StatusCode.Should().Be(HttpStatusCode.OK); var completedCompetitions = server.Assert().GetClosedCompetitions(); completedCompetitions.Should().HaveCount(1); completedCompetitions[0].WinnerAadObjectIds.Should().HaveCount(0); } }
public async Task WhenCompetitionIsCreatedAndNoCompetitorHasJoined_ViewCompetitionDetail_TaskInfoIsGeneratedWithCorrectMessageDisplayed() { var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", Locale = "en-US", OffsetHours = 8, Gift = "gift name", Status = CompetitionStatus.Active, Competitors = new List <Competitor>(), WinnerCount = 1, WinnerAadObjectIds = new List <string>() }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch(new InvokeActionData { UserAction = InvokeActionType.ViewDetail, CompetitionId = competition.Id }); response.StatusCode.Should().Be(HttpStatusCode.OK); var result = await response.Content.ReadAsWithNewtonsoftJsonAsync <TaskModuleResponseForContinue>(); result.Task?.Value?.Card?.Content.Should().NotBeNull(); var card = ((JObject)result.Task.Value.Card.Content).ToObject <AdaptiveCard>(); card.Body.Should().HaveCount(1); card.Body.First().GetType().Should().Be(typeof(AdaptiveTextBlock)); ((AdaptiveTextBlock)card.Body.First()).Text.Should().Contain("no joined users"); } }
public async Task WhenCompetitionIsCreated_ViewCompetitionDetail_TaskInfoIsGenerated() { var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", Locale = "en-US", OffsetHours = 8, Gift = "gift name", IsCompleted = false, Competitors = new List <Competitor> { new Competitor { Name = "user name", AadObjectId = "user aad object id" } }, WinnerCount = 1, WinnerAadObjectIds = new List <string>() }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch(new InvokeActionData { UserAction = InvokeActionType.ViewDetail, CompetitionId = competition.Id }); response.StatusCode.Should().Be(HttpStatusCode.OK); var result = await response.Content.ReadAsAsync <TaskModuleTaskInfoResponse>(); result.Task?.Value?.Card?.Content.Should().NotBeNull(); var card = ((JObject)result.Task.Value.Card.Content).ToObject <AdaptiveCard>(); card.Body.Should().HaveCount(1 + competition.Competitors.Count); } }
public async Task WhenDraftCompetitionIsCreatedByOthers_InvokeEditAction_ReturnsNotAllowedEdit() { var currentUserAadObjectId = Guid.NewGuid().ToString(); var creatorAadObjectId = Guid.NewGuid().ToString(); var competition = new OpenCompetitionEntity(Guid.NewGuid()) { Locale = "en-US", Gift = string.Empty, Status = CompetitionStatus.Draft, Competitors = new List <Competitor>(), WinnerAadObjectIds = new List <string>(), CreatorAadObjectId = creatorAadObjectId }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch( new InvokeActionData { UserAction = InvokeActionType.EditDraft, CompetitionId = competition.Id }, from : new ChannelAccount { AadObjectId = currentUserAadObjectId }); response.StatusCode.Should().Be(HttpStatusCode.OK); var result = await response.Content.ReadAsWithNewtonsoftJsonAsync <TaskModuleResponseForContinue>(); result.Task?.Value?.Card?.Content.Should().NotBeNull(); var card = ((JObject)result.Task.Value.Card.Content).ToObject <AdaptiveCard>(); card.Body.Should().HaveCount(1); card.Body[0].Type.Should().Be("TextBlock"); } }
public async Task UpsertOpenCompetition(Competition competition) { var entity = new OpenCompetitionEntity(competition.Id) { ServiceUrl = competition.ServiceUrl, TenantId = competition.TenantId, TeamId = competition.TeamId, ChannelId = competition.ChannelId, MainActivityId = competition.MainActivityId, ResultActivityId = competition.ResultActivityId, CreatedTime = competition.CreatedTime, PlannedDrawTime = competition.PlannedDrawTime, ActualDrawTime = competition.ActualDrawTime, Locale = competition.Locale, OffsetHours = competition.OffsetHours, Gift = competition.Gift, GiftImageUrl = competition.GiftImageUrl, WinnerCount = competition.WinnerCount, Status = competition.Status, CreatorName = competition.CreatorName, CreatorAadObjectId = competition.CreatorAadObjectId, WinnerAadObjectIds = competition.WinnerAadObjectIds, Competitors = competition.Competitors }; await OpenCompetitions.InsertOrReplace(entity); }
public async Task WhenCompetitionHasOneCompetitor_DrawCompetition_CompetitorWinsGift() { var utcNow = DateTimeOffset.UtcNow; var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", Locale = "en-US", OffsetHours = 8, PlannedDrawTime = DateTimeOffset.UtcNow.AddDays(-1), Gift = "gift name", Status = CompetitionStatus.Active, Competitors = new List <Competitor> { new Competitor { Name = "user name", AadObjectId = "user aad object id" } }, WinnerCount = 1, WinnerAadObjectIds = new List <string>() }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); arrangement.SetUtcNow(utcNow); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.PostAsync($"competitions/{competition.Id}/draw", new StringContent(string.Empty)); response.StatusCode.Should().Be(HttpStatusCode.OK); // The main activity should be updated var updatedMessages = server.Assert().GetUpdatedMessages(); updatedMessages.Should().HaveCount(1); updatedMessages[0].ReplacedActivityId.Should().Be(competition.MainActivityId); var updatedMessageHeroCard = updatedMessages[0].NewActivity.Attachments[0].Content as HeroCard; updatedMessageHeroCard.Buttons.Should().HaveCount(1); // The result activity should be created var createdMessages = server.Assert().GetCreatedMessages(); createdMessages.Should().HaveCount(1); var createdMessageHeroCard = createdMessages[0].Activity.Attachments[0].Content as HeroCard; createdMessageHeroCard.Title.Should().Contain(competition.Competitors[0].Name); // Competition data in database should be updated var openCompetitions = server.Assert().GetOpenCompetitions(); openCompetitions.Should().HaveCount(0); var completedCompetitions = server.Assert().GetClosedCompetitions(); completedCompetitions.Should().HaveCount(1); completedCompetitions[0].Status.Should().Be(CompetitionStatus.Completed); completedCompetitions[0].ActualDrawTime.Should().Be(utcNow); completedCompetitions[0].WinnerAadObjectIds.Should().HaveCount(1); completedCompetitions[0].WinnerAadObjectIds[0].Should().Be(competition.Competitors[0].AadObjectId); } }
public async Task WhenAllCompetitionPropertiesAreValid_InvokeActivationAction_CompetitionIsActivated() { var competition = new OpenCompetitionEntity(Guid.NewGuid()) { Locale = "en-US", Gift = string.Empty, Status = CompetitionStatus.Draft, Competitors = new List <Competitor>(), WinnerAadObjectIds = new List <string>() }; var activateActionData = new ActivateCompetitionInvokeActionData { UserAction = InvokeActionType.ActivateCompetition, CompetitionId = competition.Id, Gift = "new gift name", GiftImageUrl = "http://www.abc.com/new.png", WinnerCount = "988", PlannedDrawTimeLocalDate = "2028-06-18", PlannedDrawTimeLocalTime = "18:28" }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch(activateActionData); response.StatusCode.Should().Be(HttpStatusCode.NoContent); var openCompetitions = server.Assert().GetOpenCompetitions(); openCompetitions.Should().HaveCount(1); openCompetitions[0].Status.Should().Be(CompetitionStatus.Active); openCompetitions[0].Gift.Should().Be(activateActionData.Gift); openCompetitions[0].GiftImageUrl.Should().Be(activateActionData.GiftImageUrl); openCompetitions[0].WinnerCount.Should().Be(int.Parse(activateActionData.WinnerCount)); openCompetitions[0].PlannedDrawTime.Should().Be(DateTimeOffset.Parse($"{activateActionData.PlannedDrawTimeLocalDate}T{activateActionData.PlannedDrawTimeLocalTime}Z")); var updatedMessages = server.Assert().GetUpdatedMessages(); updatedMessages.Should().HaveCount(1); var heroCard = updatedMessages[0].NewActivity.Attachments[0].Content as HeroCard; heroCard.Buttons.Should().HaveCount(2); heroCard.Buttons[0].Type.Should().Be("invoke"); heroCard.Buttons[0].Value.Should().BeEquivalentTo(new InvokeActionData { UserAction = InvokeActionType.Join, CompetitionId = openCompetitions[0].Id }); heroCard.Buttons[1].Type.Should().Be("invoke"); heroCard.Buttons[1].Value.Should().BeEquivalentTo(new InvokeActionData { Type = InvokeActionData.TypeTaskFetch, UserAction = InvokeActionType.ViewDetail, CompetitionId = openCompetitions[0].Id }); } }
public async Task WhenCompetitionHasAlreadyHadSomeCompetitions_JoinCompetition_SucceedToJoin(int existingCompetitorCount) { var utcNow = DateTimeOffset.UtcNow; var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", PlannedDrawTime = DateTimeOffset.UtcNow.AddMinutes(-1), Locale = "en-US", OffsetHours = 8, Gift = "gift name", IsCompleted = false, Competitors = new List <Competitor>() }; for (int i = 0; i < existingCompetitorCount; i++) { competition.Competitors.Add(new Competitor { Name = $"existing user name {i}", AadObjectId = $"existing user aad object id {i}", JoinTime = utcNow.AddSeconds(-i) }); } var userAccount = new ChannelAccount { Name = "new user name", AadObjectId = "new user aad object id" }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); arrangement.SetUtcNow(utcNow); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var text = $"<at>bot name</at>" + "wrongFormatText"; var response = await client.SendTeamsInvoke(new InvokeActionData { UserAction = InvokeActionType.Join, CompetitionId = competition.Id }, userAccount); response.StatusCode.Should().Be(HttpStatusCode.OK); var updatedMessages = server.Assert().GetUpdatedMessages(); updatedMessages.Should().HaveCount(1); var openCompetitions = server.Assert().GetOpenCompetitions(); openCompetitions.Should().HaveCount(1); openCompetitions[0].Competitors.Should().HaveCount(existingCompetitorCount + 1); var lastCompetitor = openCompetitions[0].Competitors.Last(); lastCompetitor.Name.Should().Be(userAccount.Name); lastCompetitor.AadObjectId.Should().Be(userAccount.AadObjectId); lastCompetitor.JoinTime.Should().Be(utcNow); } }
public async Task WhenPropertyIsInvalid_InvokeActivationAction_ErrorMessageIsReturned( string gift, int winnerCount, string plannedDrawLocalDate, string plannedDrawLocalTime, string giftImageUrl, string errorText) { var competition = new OpenCompetitionEntity(Guid.NewGuid()) { Locale = "en-US", Gift = string.Empty, Status = CompetitionStatus.Draft, Competitors = new List <Competitor>(), WinnerAadObjectIds = new List <string>() }; var activateActionData = new ActivateCompetitionInvokeActionData { UserAction = InvokeActionType.ActivateCompetition, CompetitionId = competition.Id, Gift = gift, GiftImageUrl = giftImageUrl, WinnerCount = winnerCount.ToString(), PlannedDrawTimeLocalDate = plannedDrawLocalDate, PlannedDrawTimeLocalTime = plannedDrawLocalTime }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch(activateActionData); response.StatusCode.Should().Be(HttpStatusCode.OK); var result = await response.Content.ReadAsWithNewtonsoftJsonAsync <TaskModuleResponseForContinue>(); result.Task?.Value?.Card?.Content.Should().NotBeNull(); var cardBody = ((JObject)result.Task.Value.Card.Content).GetValue("body"); var errorTextBlock = ((JArray)cardBody).First.ToObject <AdaptiveTextBlock>(); errorTextBlock.Color.Should().Be(AdaptiveTextColor.Attention); errorTextBlock.Text.Should().Be(errorText); } }
public async Task WhenThereAreTwoCompetitions_DrawAllCompetitions_AllCompetitionsAreCompleted() { var competition1 = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id 1", Locale = "en-US", OffsetHours = 8, PlannedDrawTime = DateTimeOffset.UtcNow.AddDays(-1), Gift = "gift name 1", Status = CompetitionStatus.Active, Competitors = new List <Competitor>(), WinnerCount = 1, WinnerAadObjectIds = new List <string>() }; var competition2 = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id 2", Locale = "en-US", OffsetHours = 8, PlannedDrawTime = DateTimeOffset.UtcNow.AddDays(-1), Gift = "gift name 2", Status = CompetitionStatus.Active, Competitors = new List <Competitor>(), WinnerCount = 2, WinnerAadObjectIds = new List <string>() }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var openCompetitionsArrangement = server.Arrange().GetOpenCompetitions(); await openCompetitionsArrangement.InsertOrReplace(competition1); await openCompetitionsArrangement.InsertOrReplace(competition2); var response = await client.PostAsync($"competitions/draw", new StringContent(string.Empty)); response.StatusCode.Should().Be(HttpStatusCode.OK); var assertion = server.Assert(); assertion.GetUpdatedMessages().Should().HaveCount(2); assertion.GetCreatedMessages().Should().HaveCount(2); assertion.GetOpenCompetitions().Should().HaveCount(0); assertion.GetClosedCompetitions().Should().HaveCount(2); } }
public async Task WhenCompetitionIsNotCompleted_JoinCompetition_SucceedToJoin() { var utcNow = DateTimeOffset.UtcNow; var competition = new OpenCompetitionEntity(Guid.NewGuid()) { MainActivityId = "main activity id", PlannedDrawTime = DateTimeOffset.UtcNow.AddMinutes(-1), Locale = "en-US", OffsetHours = 8, Gift = "gift name", IsCompleted = false, Competitors = new List <Competitor>() }; var userAccount = new ChannelAccount { Name = "user name", AadObjectId = "user aad object id" }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); arrangement.SetUtcNow(utcNow); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsInvoke(new InvokeActionData { UserAction = InvokeActionType.Join, CompetitionId = competition.Id }, userAccount); response.StatusCode.Should().Be(HttpStatusCode.OK); var updatedMessages = server.Assert().GetUpdatedMessages(); updatedMessages.Should().HaveCount(1); updatedMessages[0].ReplacedActivityId.Should().Be(competition.MainActivityId); var heroCard = updatedMessages[0].NewActivity.Attachments[0].Content as HeroCard; heroCard.Text.Should().Contain(userAccount.Name); var openCompetitions = server.Assert().GetOpenCompetitions(); openCompetitions.Should().HaveCount(1); openCompetitions[0].Competitors.Should().HaveCount(1); openCompetitions[0].Competitors[0].Name.Should().Be(userAccount.Name); openCompetitions[0].Competitors[0].AadObjectId.Should().Be(userAccount.AadObjectId); openCompetitions[0].Competitors[0].JoinTime.Should().Be(utcNow); } }
public async Task WhenDraftCompetitionIsEdited_InvokeSaveAction_CompetitionIsUpdated() { var competition = new OpenCompetitionEntity(Guid.NewGuid()) { Locale = "en-US", Gift = string.Empty, Status = CompetitionStatus.Draft, Competitors = new List <Competitor>(), WinnerAadObjectIds = new List <string>() }; var editActionData = new SaveCompetitionInvokeActionData { UserAction = InvokeActionType.SaveDraft, CompetitionId = competition.Id, Gift = "new gift name", GiftImageUrl = "http://www.abc.com/new.png", WinnerCount = "988", PlannedDrawTimeLocalDate = "2028-06-18", PlannedDrawTimeLocalTime = "18:28" }; using (var server = CreateServerFixture(ServerFixtureConfigurations.Default)) using (var client = server.CreateClient()) { var arrangement = server.Arrange(); await arrangement.GetOpenCompetitions().InsertOrReplace(competition); var response = await client.SendTeamsTaskFetch(editActionData); response.StatusCode.Should().Be(HttpStatusCode.OK); var openCompetitions = server.Assert().GetOpenCompetitions(); openCompetitions.Should().HaveCount(1); openCompetitions[0].Gift.Should().Be(editActionData.Gift); openCompetitions[0].GiftImageUrl.Should().Be(editActionData.GiftImageUrl); openCompetitions[0].WinnerCount.Should().Be(int.Parse(editActionData.WinnerCount)); openCompetitions[0].PlannedDrawTime.Should().Be(DateTimeOffset.Parse($"{editActionData.PlannedDrawTimeLocalDate}T{editActionData.PlannedDrawTimeLocalTime}Z")); } }