Ejemplo n.º 1
0
        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
                    });
                }
        }
Ejemplo n.º 2
0
        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);
                }
        }