तो मैं रावेनडीबी और सर्विसस्टैक के साथ एक एंड टू एकीकरण परीक्षण सूट बनाने की कोशिश कर रहा था, लेकिन मैं वास्तव में एक अजीब मुद्दा में भाग गया जहां सत्यापन कुछ अनुरोधों पर नहीं चलता है। यह वास्तव में अजीब है और मुझे यकीन नहीं है कि मैं क्या गलत कर रहा हूं। मैं एनसीआरंच का उपयोग कर रहा हूँ। कभी-कभी परीक्षा पास होती है, कभी-कभी यह विफल हो जाती है।सर्विसस्टैक प्रमाणीकरण हमेशा नहीं चल रहा है
आशा है कि यह एक आसान फिक्स है और कुछ हड्डी का नेतृत्व मैं कर रहा हूं।
आप http://github.com/khalidabuhakmeh/endtoend
पर पूरी परियोजना आप से VS2012 और NuGet पैकेज सक्षम पुनर्स्थापित अन्य कुछ नहीं चाहिए डाउनलोड कर सकते हैं।
अद्यतन: मैंने इसे एनसीआरंच और रिशेर्पर टेस्ट रनर दोनों में चलाने का फैसला किया और दोनों एक ही परिणाम देते हैं [नीचे छवि देखें]।
अद्यतन अद्यतन: मैंने सोचा कि यह XUnit हो सकता है, इसलिए मैंने NUnit का उपयोग करने की कोशिश की। अभी भी एक ही समस्या नहीं है।
** एक और अद्यतन: कंसोल में रखो user1901853 के अनुरोध के अनुसार लिखता है। यह परिणाम था "
नवीनतम अद्यतन:। RequestFilters का सफाया कर रहे हैं हो रही है और मुझे यकीन है कि नहीं कर रहा हूँ क्यों ऐसा लगता है जैसे कि यह एक सूत्रण समस्या हो सकती है, लेकिन मैं नहीं देख सकते हैं। ।
मेरे AppHost उपयोग कर रहा है AppHostListenerBase
using EndToEnd.Core;
using Funq;
using Raven.Client;
using ServiceStack.ServiceInterface.Validation;
using ServiceStack.WebHost.Endpoints;
namespace EndToEnd
{
public class TestAppHost
: AppHostHttpListenerBase
{
private readonly IDocumentStore _documentStore;
public TestAppHost(IDocumentStore documentStore)
: base("Test AppHost Api", typeof(TestAppHost).Assembly)
{
_documentStore = documentStore;
}
public override void Configure(Container container)
{
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
// Register RavenDB things
container.Register(_documentStore);
container.Register(c =>
{
var db = c.Resolve<IDocumentStore>();
return db.OpenSession();
}).ReusedWithin(ReuseScope.Request);
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(CreateWidgetValidator).Assembly);
// todo: register all of your plugins here
AuthConfig.Start(this, container);
}
}
}
मेरी परीक्षण के सभी के लिए मेरे आधार परीक्षण वर्ग इस तरह दिखता है:।
using Raven.Client;
using Raven.Client.Indexes;
using Raven.Tests.Helpers;
using ServiceStack.Authentication.RavenDb;
using ServiceStack.ServiceClient.Web;
using ServiceStack.ServiceInterface.Auth;
namespace EndToEnd
{
public abstract class ServiceStackTestBase
: RavenTestBase
{
protected IDocumentStore DocumentStore { get; set; }
protected TestAppHost Host { get; set; }
protected JsonServiceClient Client { get; set; }
protected const string ListeningOn = "http://localhost:1337/";
protected string Username { get { return "testuser"; } }
protected string Password { get { return "password"; } }
protected ServiceStackTestBase()
{
DocumentStore = NewDocumentStore();
IndexCreation.CreateIndexes(typeof(ServiceStackTestBase).Assembly, DocumentStore);
IndexCreation.CreateIndexes(typeof(RavenUserAuthRepository).Assembly, DocumentStore);
Host = new TestAppHost(DocumentStore);
Host.Init();
Host.Start(ListeningOn);
Client = new JsonServiceClient(ListeningOn)
{
AlwaysSendBasicAuthHeader = true,
UserName = Username,
Password = Password
};
RegisterUser();
WaitForIndexing(DocumentStore);
}
private void RegisterUser()
{
Client.Send(new Registration
{
UserName = Username,
Password = Password,
DisplayName = "Test User",
Email = "[email protected]",
FirstName = "test",
LastName = "user"
});
}
public override void Dispose()
{
DocumentStore.Dispose();
Host.Dispose();
}
}
}
अपने परीक्षण वर्ग इस तरह दिखता है:
using System;
using EndToEnd.Core;
using FluentAssertions;
using ServiceStack.FluentValidation;
using ServiceStack.ServiceClient.Web;
using ServiceStack.ServiceInterface.Auth;
using Xunit;
namespace EndToEnd
{
public class RegistrationTests
: ServiceStackTestBase
{
[Fact]
public void Throws_validation_exception_when_bad_widget()
{
var validator = Host.Container.Resolve<IValidator<CreateWidget>>();
validator.Should().NotBeNull();
try
{
var response = Client.Post(new CreateWidget
{
Name = null
});
// It get's here every once in a while
throw new Exception("Should Not Get Here!");
}
catch (WebServiceException wex)
{
wex.StatusCode.Should().Be(400);
wex.ErrorMessage.Should().Be("'Name' should not be empty.");
}
}
}
}
मेरे कोड सेवा के लिए इस तरह दिखता है:
using System;
using Raven.Client;
using ServiceStack.FluentValidation;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.ServiceModel;
namespace EndToEnd.Core
{
[Authenticate]
public class WidgetsService
: Service
{
private readonly IDocumentSession _session;
public WidgetsService(IDocumentSession session)
{
_session = session;
}
public CreateWidgetResponse Post(CreateWidget input)
{
var widget = new Widget { Name = input.Name };
_session.Store(widget);
_session.SaveChanges();
return new CreateWidgetResponse { Widget = widget };
}
}
[Route("/widgets", "POST")]
public class CreateWidget : IReturn<CreateWidgetResponse>
{
public string Name { get; set; }
}
public class CreateWidgetResponse
{
public CreateWidgetResponse()
{
ResponseStatus = new ResponseStatus();
}
public Widget Widget { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
public class Widget
{
public Widget()
{
Created = DateTimeOffset.UtcNow;
}
public string Id { get; set; }
public string Name { get; set; }
public DateTimeOffset Created { get; set; }
}
public class CreateWidgetValidator : AbstractValidator<CreateWidget>
{
public CreateWidgetValidator()
{
RuleFor(m => m.Name).NotEmpty();
}
}
}
अपने रेपो को क्लोन किया गया है, जो आपने कहा है उसे दोहरा सकते हैं। कुछ पैटर्न खोजने की कोशिश कर रहा है। क्या आपने लॉगिंग सक्षम करने का प्रयास किया है? मुझे आश्चर्य है कि POST अनुरोध कैश हो रहा है, क्योंकि जब आपका 'Throws_validation_exception_when_bad_widget' पहले चलता है, तो यह गुजरता है। जब यह दो अन्य में से किसी एक के बाद चलता है तो यह विफल रहता है। –
यह समझ में आता है, कैशिंग बंद करने का कोई तरीका है? –
वास्तव में केवल दो बार चेक किया गया है, और मैं एक कैशिंग प्रदाता पंजीकृत नहीं करता हूं, और मुझे याद है कि अनुरोध फ़िल्टर "कभी-कभी" साफ़ हो जाता है। –