Пример #1
0
 private void SetupFirewallResponse(FirewallRuleResponse response)
 {
     ResourceManagerMock.Setup(r => r.CreateFirewallRuleAsync(
                                   It.IsAny <IAzureResourceManagementSession>(),
                                   It.IsAny <IAzureSqlServerResource>(),
                                   It.IsAny <FirewallRuleRequest>())
                               ).Returns(() => Task.FromResult(response));
 }
Пример #2
0
 private void SetupCreateSession()
 {
     ResourceManagerMock.Setup(r => r.CreateSessionAsync(It.IsAny <IAzureUserAccountSubscriptionContext>()))
     .Returns((IAzureUserAccountSubscriptionContext sub) =>
     {
         var sessionMock = new Mock <IAzureResourceManagementSession>();
         sessionMock.SetupProperty(s => s.SubscriptionContext, sub);
         return(Task.FromResult(sessionMock.Object));
     });
 }
Пример #3
0
        private void SetupAzureServers(IAzureSubscriptionContext sub, IEnumerable <IAzureSqlServerResource> servers)
        {
            Func <IAzureResourceManagementSession, bool> isExpectedSub = (session) =>
            {
                return(session.SubscriptionContext == sub);
            };

            ResourceManagerMock.Setup(r => r.GetSqlServerAzureResourcesAsync(
                                          It.Is <IAzureResourceManagementSession>((session) => isExpectedSub(session))
                                          )).Returns(() => Task.FromResult(servers));
        }
Пример #4
0
        public void Validate_ResponseStreamNotAsExpected_ValidationFails()
        {
            // Arrange
            const string             fileId          = "fileId";
            MemoryStream             responseStream  = new MemoryStream(Encoding.UTF8.GetBytes("my content"));
            MemoryStream             expectedStream  = new MemoryStream();
            ResponseContentValidator validator       = new ResponseContentValidator(fileId);
            ResourceManagerMock      resourceManager = new ResourceManagerMock {
                { fileId, expectedStream }
            };
            ResponseDataMock responseData = new ResponseDataMock {
                ResponseStream = responseStream
            };

            // Act
            ValidationResult validationResult = validator.Validate(responseData, resourceManager, null);

            // Assert
            Assert.IsTrue(validationResult.HasFailures);
        }
Пример #5
0
        public void Validate_ResponseStreamNotAsExpected_OneErrorReturned()
        {
            // Arrange
            const string             fileId          = "fileId";
            MemoryStream             responseStream  = new MemoryStream(Encoding.UTF8.GetBytes("my content"));
            MemoryStream             expectedStream  = new MemoryStream();
            ResponseContentValidator validator       = new ResponseContentValidator(fileId);
            ResourceManagerMock      resourceManager = new ResourceManagerMock {
                { fileId, expectedStream }
            };
            ResponseDataMock responseData = new ResponseDataMock {
                ResponseStream = responseStream
            };

            // Act
            ValidationResult validationResult = validator.Validate(responseData, resourceManager, null);

            // Assert
            Assert.IsNotNull(validationResult.Errors);
            Assert.AreEqual(1, validationResult.Errors.Count());
        }
Пример #6
0
        public void Validate_BodyAsExpected_ValidationSucceeds()
        {
            // Arrange
            const string             fileId          = "fileId";
            const string             content         = "my content";
            MemoryStream             responseStream  = new MemoryStream(Encoding.UTF8.GetBytes(content));
            MemoryStream             expectedStream  = new MemoryStream(Encoding.UTF8.GetBytes(content));
            ResponseContentValidator validator       = new ResponseContentValidator(null, content);
            ResourceManagerMock      resourceManager = new ResourceManagerMock {
                { fileId, expectedStream }
            };
            ResponseDataMock responseData = new ResponseDataMock {
                ResponseStream = responseStream
            };

            // Act
            ValidationResult validationResult = validator.Validate(responseData, resourceManager, null);

            // Assert
            Assert.IsFalse(validationResult.HasFailures);
        }