﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Moq;
using Moq.Protected;
using NUnit.Framework;
using Virtlink.Caching;
using static Virtlink.TestUtils.Test;

namespace Virtlink.Vfs
{
	partial class ReadOnlyVirtualFileTests
	{
		/// <summary>
		/// Tests the <see cref="ReadOnlyVirtualFile.Attach"/> method.
		/// </summary>
		[TestFixture]
		public class AttachTests : ReadOnlyVirtualFileTests
		{
			[Test]
			public void CallsDoAttachWhenObjectIsNotAttached()
			{
				// Arrange
				var mock = CreateMock();
				var sut = mock.Object;

				// Assume
				Assume.That(sut.IsAttached, Is.False);

				// Act
				sut.Attach();

				// Assert
				mock.Protected().Verify("DoAttach", Times.Once());
			}

			[Test]
			public void DoesNotCallDoAttachWhenObjectIsAttached()
			{
				// Arrange
				var mock = CreateMock();
				var sut = mock.Object;
				sut.Attach();
				mock.ResetCalls();

				// Assume
				Assume.That(sut.IsAttached, Is.True);

				// Act
				sut.Attach();

				// Assert
				mock.Protected().Verify("DoAttach", Times.Never());
			}

			[Test]
			public void IsNotAttachedOnDoAttachCall()
			{
				// Arrange
				var mock = CreateMock();
				var sut = mock.Object;
				mock.Protected().Setup("DoAttach").Callback(() =>
				{
					// Assert
					Assert.That(sut.IsAttached, Is.False);
				});

				// Act
				sut.Attach();
			}

			[Test]
			public void AtReturnIsAttachedIsTrue()
			{
				// Arrange
				var mock = CreateMock();
				var sut = mock.Object;

				// Act
				sut.Attach();

				// Assert
				Assert.That(sut.IsAttached, Is.True);
			}
		}
	}
}
