<commit_before>﻿// ==========================================================================
//  AssetCommandHandlerTests.cs
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex Group
//  All rights reserved.
// ==========================================================================

using System;
using System.IO;
using System.Threading.Tasks;
using Squidex.Infrastructure.Assets;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Write.Assets.Commands;
using Squidex.Write.TestHelpers;
using Xunit;
using Moq;
using Squidex.Infrastructure.Tasks;

// ReSharper disable ConvertToConstant.Local

namespace Squidex.Write.Assets
{
    public class AssetCommandHandlerTests : HandlerTestBase<AssetDomainObject>
    {
        private readonly Mock<IAssetThumbnailGenerator> assetThumbnailGenerator = new Mock<IAssetThumbnailGenerator>();
        private readonly Mock<IAssetStore> assetStore = new Mock<IAssetStore>();
        private readonly AssetCommandHandler sut;
        private readonly AssetDomainObject asset;
        private readonly Guid assetId = Guid.NewGuid();
        private readonly Stream stream = new MemoryStream();
        private readonly ImageInfo image = new ImageInfo(2048, 2048);
        private readonly AssetFile file;

        public AssetCommandHandlerTests()
        {
            file = new AssetFile("my-image.png", "image/png", 1024, () => stream);

            asset = new AssetDomainObject(assetId, -1);

            sut = new AssetCommandHandler(Handler, assetStore.Object, assetThumbnailGenerator.Object);
        }

        [Fact]
        public async Task Create_should_create_asset()
        {
            SetupStore(1);
            SetupImageInfo();

            var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file });

            await TestCreate(asset, async _ =>
            {
                await sut.HandleAsync(context);
            });

            Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);

            assetStore.VerifyAll();
            assetThumbnailGenerator.VerifyAll();
        }

        [Fact]
        public async Task Update_should_update_domain_object()
        {
            SetupStore(2);<commit_msg>1) Tests fixed 2) Versions bumped<commit_after>﻿// ==========================================================================
//  AssetCommandHandlerTests.cs
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex Group
//  All rights reserved.
// ==========================================================================

using System;
using System.IO;
using System.Threading.Tasks;
using Squidex.Infrastructure.Assets;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Write.Assets.Commands;
using Squidex.Write.TestHelpers;
using Xunit;
using Moq;
using Squidex.Infrastructure.Tasks;

// ReSharper disable ConvertToConstant.Local

namespace Squidex.Write.Assets
{
    public class AssetCommandHandlerTests : HandlerTestBase<AssetDomainObject>
    {
        private readonly Mock<IAssetThumbnailGenerator> assetThumbnailGenerator = new Mock<IAssetThumbnailGenerator>();
        private readonly Mock<IAssetStore> assetStore = new Mock<IAssetStore>();
        private readonly AssetCommandHandler sut;
        private readonly AssetDomainObject asset;
        private readonly Guid assetId = Guid.NewGuid();
        private readonly Stream stream = new MemoryStream();
        private readonly ImageInfo image = new ImageInfo(2048, 2048);
        private readonly AssetFile file;

        public AssetCommandHandlerTests()
        {
            file = new AssetFile("my-image.png", "image/png", 1024, () => stream);

            asset = new AssetDomainObject(assetId, -1);

            sut = new AssetCommandHandler(Handler, assetStore.Object, assetThumbnailGenerator.Object);
        }

        [Fact]
        public async Task Create_should_create_asset()
        {
            SetupStore(0);
            SetupImageInfo();

            var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file });

            await TestCreate(asset, async _ =>
            {
                await sut.HandleAsync(context);
            });

            Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);

            assetStore.VerifyAll();
            assetThumbnailGenerator.VerifyAll();
        }

        [Fact]
        public async Task Update_should_update_domain_object()
        {
            SetupStore(1);
{'fraction_non_alphanumeric': 0.17639484978540773, 'fraction_numerical': 0.0068669527896995704, 'mean_word_length': 3.1765232974910393, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '676441', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1133, 'n_words': 264}