﻿using System;
using System.ServiceModel;
using Hardcore.Web.TestCommon.Wcf;
using Hardcore.Web.Wcf;
using NUnit.Framework;

namespace Hardcore.Web.IntegrationTest.Wcf.Injection
{
    [TestFixture]
    public class BizFaultInjectionBehavior
    {
        [Test]
        public void ShouldSupportBizFault()
        {
            //Arrange
            var ch = TestServiceProvider.CreteClient<BizFaultInjectionTest.IService>(nameof(BizFaultInjectionBehavior));

            FaultException fault = null;
            const string faultId = "faultId";
            DateTime faultTime = DateTime.Now;
            const string faultSource = "faultSource";

            //Act

            try
            {
                ch.ThrowBizFault(faultId, faultTime, faultSource);
            }
            catch (FaultException e)
            {
                fault = e;
            }

            //Assert
            var bizFaut = fault as FaultException<BizFaultDetails>;

            Assert.IsNotNull(fault, "No fault catched");
            Assert.IsNotNull(bizFaut, "The catched fault is not Biz");
            Assert.AreEqual(BizFaultInjectionTest.FaultText, fault.Message);
            Assert.IsNotNull(bizFaut.Detail);
            Assert.AreEqual(faultId, bizFaut.Detail.Id);
            Assert.AreEqual(faultTime, bizFaut.Detail.Time);
            Assert.AreEqual(faultSource, bizFaut.Detail.Source);
        }
    }
}
