Beispiel #1
0
        public async Task Update_Sponsor()
        {
            await AddNewSponsor();

            var sponsor = Context.Sponsors.FirstOrDefault();

            var file1     = File.OpenRead(@"Images\Blanco.png");
            var badgeFile = new StreamContent(file1);
            var formData  = new MultipartFormDataContent();

            formData.Add(badgeFile, nameof(NewSponsorCommand.ImageFile), $"NewImage.jpg");
            formData.Add(new StringContent("New Name"), nameof(NewSponsorCommand.Name));
            formData.Add(new StringContent("New Description"), nameof(NewSponsorCommand.Description));
            formData.Add(new StringContent("New SiteUrl"), nameof(NewSponsorCommand.SiteUrl));
            formData.Add(new StringContent("New Email"), nameof(NewSponsorCommand.Email));

            var response = await HttpClient.PutAsync($"/sponsors/{sponsor.Id}", formData);

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var oldLogoFileName = sponsor.LogoFileName;

            RefreshContext();
            sponsor = Context.Sponsors.FirstOrDefault();
            sponsor.Name.Should().Be("New Name");
            sponsor.Description.Should().Be("New Description");
            sponsor.SiteUrl.Should().Be("New SiteUrl");
            sponsor.Email.Should().Be("New Email");

            (await FileServices.GetAsync(oldLogoFileName, Api.Services.Container.Sponsors)).Should().BeNull();
            (await FileServices.GetAsync(sponsor.LogoFileName, Api.Services.Container.Sponsors)).Should().NotBeNull();
            await FileServices.DeleteAsync(sponsor.LogoFileName, Api.Services.Container.Sponsors);
        }
        public async Task Update_Badge()
        {
            await AddNewBadge();

            var badge = Context.Badges.FirstOrDefault();

            var file1     = File.OpenRead(@"Images\Blanco.png");
            var badgeFile = new StreamContent(file1);

            badgeFile.Headers.Add("BadgeType", BadgeImageName.Badge.ToString());
            var simpleBadgeFile = new StreamContent(file1);

            simpleBadgeFile.Headers.Add("BadgeType", BadgeImageName.SimpleBadge.ToString());
            var linkedinBadgeFile = new StreamContent(file1);

            linkedinBadgeFile.Headers.Add("BadgeType", BadgeImageName.LinkedinBadge.ToString());

            var formData = new MultipartFormDataContent();

            formData.Add(badgeFile, nameof(UpdateBadgeCommand.ImageFiles), $"{BadgeImageName.Badge}.jpg");
            formData.Add(simpleBadgeFile, nameof(UpdateBadgeCommand.ImageFiles), $"{BadgeImageName.SimpleBadge}.jpg");
            formData.Add(linkedinBadgeFile, nameof(UpdateBadgeCommand.ImageFiles), $"{BadgeImageName.LinkedinBadge}.jpg");
            formData.Add(new StringContent("New Name"), nameof(UpdateBadgeCommand.Name));
            formData.Add(new StringContent("New Description"), nameof(UpdateBadgeCommand.Description));

            await HttpClient.PutAsync($"/badges/{badge.Id}", formData);

            var oldImageName       = badge.ImageName;
            var oldSimpleImageName = badge.SimpleImageName;

            Context.Entry(badge).Reload();
            badge.Name.Should().Be("New Name");
            badge.Description.Should().Be("New Description");

            (await FileServices.GetAsync(oldImageName, Api.Services.Container.Badges)).Should().BeNull();
            (await FileServices.GetAsync(oldSimpleImageName, Api.Services.Container.Badges)).Should().BeNull();

            (await FileServices.GetAsync(badge.ImageName, Api.Services.Container.Badges)).Should().NotBeNull();
            (await FileServices.GetAsync(badge.SimpleImageName, Api.Services.Container.Badges)).Should().NotBeNull();
            (await FileServices.GetAsync(badge.LinkedinImageName, Api.Services.Container.Badges)).Should().NotBeNull();

            await FileServices.DeleteAsync(badge.ImageName, Api.Services.Container.Badges);

            await FileServices.DeleteAsync(badge.SimpleImageName, Api.Services.Container.Badges);

            await FileServices.DeleteAsync(badge.LinkedinImageName, Api.Services.Container.Badges);
        }
        public async Task Add_New_Badge()
        {
            var file1     = File.OpenRead(@"Images\Blanco.png");
            var badgeFile = new StreamContent(file1);

            badgeFile.Headers.Add("BadgeType", BadgeImageName.Badge.ToString());
            var simpleBadgeFile = new StreamContent(file1);

            simpleBadgeFile.Headers.Add("BadgeType", BadgeImageName.SimpleBadge.ToString());

            var linkedinBadgeFile = new StreamContent(file1);

            linkedinBadgeFile.Headers.Add("BadgeType", BadgeImageName.LinkedinBadge.ToString());

            var formData = new MultipartFormDataContent();

            formData.Add(badgeFile, nameof(NewBadgeCommand.ImageFiles), $"{BadgeImageName.Badge}.jpg");
            formData.Add(simpleBadgeFile, nameof(NewBadgeCommand.ImageFiles), $"{BadgeImageName.SimpleBadge}.jpg");
            formData.Add(linkedinBadgeFile, nameof(NewBadgeCommand.ImageFiles), $"{BadgeImageName.LinkedinBadge}.jpg");
            formData.Add(new StringContent(nameof(NewBadgeCommand.Name)), "Name");
            formData.Add(new StringContent(nameof(NewBadgeCommand.Description)), "Description");

            var response = await HttpClient.PostAsync("/badges", formData);



            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            var badge = Context.Badges.FirstOrDefault();

            badge.Name.Should().Be("Name");
            badge.Created.Date.Should().Be(DateTime.Now.Date);
            badge.Description.Should().Be("Description");
            (await FileServices.GetAsync(badge.ImageName, Api.Services.Container.Badges)).Should().NotBeNull();
            (await FileServices.GetAsync(badge.SimpleImageName, Api.Services.Container.Badges)).Should().NotBeNull();
            (await FileServices.GetAsync(badge.LinkedinImageName, Api.Services.Container.Badges)).Should().NotBeNull();

            await FileServices.DeleteAsync(badge.ImageName, Api.Services.Container.Badges);

            await FileServices.DeleteAsync(badge.SimpleImageName, Api.Services.Container.Badges);

            await FileServices.DeleteAsync(badge.LinkedinImageName, Api.Services.Container.Badges);
        }