Exemplo n.º 1
0
        public void IfUserSetDebugOptionRequestAndErrorsShouldBeWritedToTrace()
        {
            var localName  = "test_multi_pages.docx";
            var remoteName = "IfUserSetDebugOptionRequestAndErrorsShouldBeWritedToTrace.docx";
            var fullName   = Path.Combine(this.dataFolder, remoteName);
            var request    = new DeleteFieldsRequest(remoteName, this.dataFolder);
            var api        = new WordsApi(new Configuration {
                ApiBaseUrl = BaseProductUri, AppKey = AppKey, AppSid = AppSID, DebugMode = true
            });

            var mockFactory       = new MockFactory();
            var traceListenerMock = mockFactory.CreateMock <TraceListener>();

            Trace.Listeners.Add(traceListenerMock.MockObject);

            this.StorageApi.PutCreate(fullName, null, null, File.ReadAllBytes(BaseTestContext.GetDataDir(BaseTestContext.CommonFolder) + localName));

            traceListenerMock.Expects.One.Method(p => p.WriteLine(string.Empty)).With(Is.StringContaining("DELETE: http://api-dev.aspose.cloud/v1.1/words/IfUserSetDebugOptionRequestAndErrorsShouldBeWritedToTrace.docx/fields"));
            traceListenerMock.Expects.One.Method(p => p.WriteLine(string.Empty)).With(Is.StringContaining("Response 200: OK"));
            traceListenerMock.Expects.One.Method(p => p.WriteLine(string.Empty)).With(Is.StringContaining("{\"Code\":200,\"Status\":\"OK\"}"));

            traceListenerMock.Expects.AtLeastOne.Method(p => p.WriteLine(string.Empty)).With(Is.Anything);

            // Act
            api.DeleteFields(request);

            // Assert
            mockFactory.VerifyAllExpectationsHaveBeenMet();
        }
Exemplo n.º 2
0
        public void IfUserSetDebugOptionRequestAndErrorsShouldBeWroteToTrace()
        {
            var localName  = "test_multi_pages.docx";
            var remoteName = "IfUserSetDebugOptionRequestAndErrorsShouldBeWritedToTrace.docx";
            var fullName   = Path.Combine(this.dataFolder, remoteName);
            var request    = new DeleteFieldsRequest(remoteName, null, this.dataFolder);
            var api        = new WordsApi(
                new Configuration
            {
                ClientId     = this.ClientId,
                ClientSecret = this.ClientSecret,
                ApiBaseUrl   = this.BaseProductUri,
                DebugMode    = true
            });

            this.UploadFileToStorage(
                fullName,
                null,
                null,
                File.ReadAllBytes(BaseTestContext.GetDataDir(BaseTestContext.CommonFolder) + localName));

            var traceListenerMock = new Mock <TraceListener>();

            traceListenerMock.Setup(x => x.WriteLine(It.IsAny <string>())).Verifiable();
            Trace.Listeners.Add(traceListenerMock.Object);

            try
            {
                // Act
                api.DeleteFields(request);

                // Assert
                traceListenerMock.Verify(x => x.WriteLine(It.Is <string>(s => s.Contains("grant_type=client_credentials"))), Times.Once);
                traceListenerMock.Verify(x => x.WriteLine(It.Is <string>(s => s.Contains($"DELETE: {this.BaseProductUri}/v4.0/words/IfUserSetDebugOptionRequestAndErrorsShouldBeWritedToTrace.docx/fields"))), Times.Once);
                traceListenerMock.Verify(x => x.WriteLine(It.Is <string>(s => s.Contains("Response 200: OK"))), Times.Exactly(2));
            }
            finally
            {
                Trace.Listeners.Remove(traceListenerMock.Object);
            }
        }