Beispiel #1
0
    public async Task RedirectsToLoginIfNotAuthenticated()
    {
        // Load Home Page
        var response = await Client.GetAsync("/");

        response.EnsureSuccessStatusCode();
        var stringResponse1 = await response.Content.ReadAsStringAsync();

        string token = WebPageHelpers.GetRequestVerificationToken(stringResponse1);

        // Add Item to Cart
        var keyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("id", "2"),
            new KeyValuePair <string, string>("name", "shirt"),
            new KeyValuePair <string, string>("price", "19.49"),
            new KeyValuePair <string, string>("__RequestVerificationToken", token)
        };
        var formContent  = new FormUrlEncodedContent(keyValues);
        var postResponse = await Client.PostAsync("/basket/index", formContent);

        postResponse.EnsureSuccessStatusCode();
        var stringResponse = await postResponse.Content.ReadAsStringAsync();

        Assert.Contains(".NET Black &amp; White Mug", stringResponse);

        keyValues.Clear();

        formContent = new FormUrlEncodedContent(keyValues);
        var postResponse2 = await Client.PostAsync("/Basket/Checkout", formContent);

        Assert.Contains("/Identity/Account/Login", postResponse2.RequestMessage.RequestUri.ToString());
    }
Beispiel #2
0
    public async Task ReturnsFormWithRequestVerificationToken()
    {
        var response = await Client.GetAsync("/identity/account/login");

        response.EnsureSuccessStatusCode();
        var stringResponse = await response.Content.ReadAsStringAsync();

        string token = WebPageHelpers.GetRequestVerificationToken(stringResponse);

        Assert.True(token.Length > 50);
    }
Beispiel #3
0
    public async Task SucessfullyPay()
    {
        // Load Home Page
        var response = await Client.GetAsync("/");

        response.EnsureSuccessStatusCode();
        var stringResponse = await response.Content.ReadAsStringAsync();

        // Add Item to Cart
        var keyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("id", "2"),
            new KeyValuePair <string, string>("name", "shirt"),
            new KeyValuePair <string, string>("price", "19.49"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringResponse))
        };
        var formContent  = new FormUrlEncodedContent(keyValues);
        var postResponse = await Client.PostAsync("/basket/index", formContent);

        postResponse.EnsureSuccessStatusCode();
        var stringPostResponse = await postResponse.Content.ReadAsStringAsync();

        Assert.Contains(".NET Black &amp; White Mug", stringPostResponse);

        //Load login page
        var loginResponse = await Client.GetAsync("/Identity/Account/Login");

        var longinKeyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("email", "*****@*****.**"),
            new KeyValuePair <string, string>("password", "Pass@word1"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(await loginResponse.Content.ReadAsStringAsync()))
        };
        var loginFormContent  = new FormUrlEncodedContent(longinKeyValues);
        var loginPostResponse = await Client.PostAsync("/Identity/Account/Login?ReturnUrl=%2FBasket%2FCheckout", loginFormContent);

        var loginStringResponse = await loginPostResponse.Content.ReadAsStringAsync();

        //Basket checkout (Pay now)
        var checkOutKeyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("Items[0].Id", "2"),
            new KeyValuePair <string, string>("Items[0].Quantity", "1"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(loginStringResponse))
        };
        var checkOutContent  = new FormUrlEncodedContent(checkOutKeyValues);
        var checkOutResponse = await Client.PostAsync("/basket/checkout", checkOutContent);

        var stringCheckOutResponse = await checkOutResponse.Content.ReadAsStringAsync();

        Assert.Contains("/Basket/Success", checkOutResponse.RequestMessage.RequestUri.ToString());
        Assert.Contains("Thanks for your Order!", stringCheckOutResponse);
    }
Beispiel #4
0
    public async Task OnPostUpdateTo50Successfully()
    {
        // Load Home Page
        var response = await Client.GetAsync("/");

        response.EnsureSuccessStatusCode();
        var stringResponse1 = await response.Content.ReadAsStringAsync();

        string token = WebPageHelpers.GetRequestVerificationToken(stringResponse1);

        // Add Item to Cart
        var keyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("id", "2"),
            new KeyValuePair <string, string>("name", "shirt"),
            new KeyValuePair <string, string>("__RequestVerificationToken", token)
        };
        var formContent  = new FormUrlEncodedContent(keyValues);
        var postResponse = await Client.PostAsync("/basket/index", formContent);

        postResponse.EnsureSuccessStatusCode();
        var stringResponse = await postResponse.Content.ReadAsStringAsync();

        Assert.Contains(".NET Black &amp; White Mug", stringResponse);

        //Update
        var updateKeyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("Items[0].Id", WebPageHelpers.GetId(stringResponse)),
            new KeyValuePair <string, string>("Items[0].Quantity", "49"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringResponse))
        };
        var updateContent  = new FormUrlEncodedContent(updateKeyValues);
        var updateResponse = await Client.PostAsync("/basket/update", updateContent);

        var stringUpdateResponse = await updateResponse.Content.ReadAsStringAsync();

        Assert.Contains("/basket/update", updateResponse.RequestMessage.RequestUri.ToString());
        decimal expectedTotalAmount = 416.50M;

        Assert.Contains(expectedTotalAmount.ToString("N2"), stringUpdateResponse);
    }
Beispiel #5
0
    public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials()
    {
        var getResponse = await Client.GetAsync("/identity/account/login");

        getResponse.EnsureSuccessStatusCode();
        var stringResponse1 = await getResponse.Content.ReadAsStringAsync();

        var keyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("Email", "*****@*****.**"),
            new KeyValuePair <string, string>("Password", "Pass@word1"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringResponse1))
        };
        var formContent = new FormUrlEncodedContent(keyValues);

        var postResponse = await Client.PostAsync("/identity/account/login", formContent);

        Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode);
        Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location);
    }
Beispiel #6
0
    public async Task UpdatePhoneNumberProfile()
    {
        //Login
        var getResponse = await Client.GetAsync("/identity/account/login");

        getResponse.EnsureSuccessStatusCode();
        var stringResponse1 = await getResponse.Content.ReadAsStringAsync();

        var keyValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("Email", "*****@*****.**"),
            new KeyValuePair <string, string>("Password", "Pass@word1"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringResponse1))
        };
        var formContent = new FormUrlEncodedContent(keyValues);
        await Client.PostAsync("/identity/account/login", formContent);

        //Profile page
        var profileResponse = await Client.GetAsync("/manage/my-account");

        profileResponse.EnsureSuccessStatusCode();
        var stringProfileResponse = await profileResponse.Content.ReadAsStringAsync();

        //Update phone number
        var updateProfileValues = new List <KeyValuePair <string, string> >
        {
            new KeyValuePair <string, string>("Email", "*****@*****.**"),
            new KeyValuePair <string, string>("PhoneNumber", "03656565"),
            new KeyValuePair <string, string>(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(stringProfileResponse))
        };
        var updateProfileContent = new FormUrlEncodedContent(updateProfileValues);
        var postProfileResponse  = await Client.PostAsync("/manage/my-account", updateProfileContent);

        Assert.Equal(HttpStatusCode.Redirect, postProfileResponse.StatusCode);
        var profileResponse2 = await Client.GetAsync("/manage/my-account");

        var stringProfileResponse2 = await profileResponse2.Content.ReadAsStringAsync();

        Assert.Contains("03656565", stringProfileResponse2);
    }