mirror of
https://github.com/opengram-server/opengram.git
synced 2026-07-21 13:10:16 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
//namespace MyTelegram.Domain.Tests.UnitTests.Sagas;
|
||||
|
||||
//public class MessageSagaTests : TestsFor<MessageSaga>
|
||||
//{
|
||||
// //private Mock<ICommandBus> _commandBus;
|
||||
// private readonly Mock<ISagaContext> _sagaContext;
|
||||
// private readonly int _messageId = 1;
|
||||
|
||||
// public MessageSagaTests()
|
||||
// {
|
||||
// Fixture.Customize<MessageSagaId>(c => c.FromFactory(() => new MessageSagaId($"messagesaga-{Guid.Empty}")));
|
||||
// //_commandBus = InjectMock<ICommandBus>();
|
||||
// _sagaContext = InjectMock<ISagaContext>();
|
||||
// }
|
||||
|
||||
// [Theory]
|
||||
// [MemberData(nameof(GetSendMessageData))]
|
||||
// public async Task SendMessage_Started_Test(Peer fromPeer, Peer toPeer)
|
||||
// {
|
||||
// var aggregateId = MessageId.Create(fromPeer.PeerId, _messageId);
|
||||
// var messageItem = new MessageItem(
|
||||
// fromPeer,
|
||||
// toPeer,
|
||||
// fromPeer,
|
||||
// _messageId,
|
||||
// "test message",
|
||||
// A<int>(),
|
||||
// A<long>(),
|
||||
// true);
|
||||
// var aggregateEvent = new SendMessageStartedEvent(A<RequestInfo>(),
|
||||
// messageItem,
|
||||
// true,
|
||||
// 1,
|
||||
// false,
|
||||
// Guid.NewGuid()
|
||||
// );
|
||||
// var domainEvent = ADomainEvent<MessageAggregate, MessageId, SendMessageStartedEvent>(aggregateEvent, aggregateId, 1);
|
||||
|
||||
// await Sut.HandleAsync(domainEvent, _sagaContext.Object, CancellationToken.None);
|
||||
|
||||
// var uncommittedEvent = Sut.UncommittedEvents.Single().AggregateEvent.ShouldBeOfType<MessageSagaStartedEvent>();
|
||||
// uncommittedEvent.MessageItem.ToPeer.ShouldBe(toPeer);
|
||||
// }
|
||||
|
||||
// //[Fact]
|
||||
// //public async Task SendMessage_To_User_Peer_Started_Test()
|
||||
// //{
|
||||
// // var fromPeer = new Peer(PeerType.User, 1);
|
||||
// // var toPeer = new Peer(PeerType.User, 2);
|
||||
// // var aggregateId = MessageId.Create(fromPeer.PeerId, _messageId);
|
||||
// // var messageItem = new MessageItem(aggregateId,
|
||||
// // fromPeer,
|
||||
// // toPeer,
|
||||
// // fromPeer,
|
||||
// // _messageId,
|
||||
// // "test message",
|
||||
// // A<int>(),
|
||||
// // A<long>(),
|
||||
// // true);
|
||||
// // var aggregateEvent = new SendMessageStartedEvent(A<RequestInfo>(),
|
||||
// // messageItem,
|
||||
// // true,
|
||||
// // 1,
|
||||
// // Guid.NewGuid()
|
||||
// // );
|
||||
// // var domainEvent = ADomainEvent<MessageAggregate, MessageId, SendMessageStartedEvent>(aggregateEvent, aggregateId, 1);
|
||||
// // _commandBus.Setup(c => c.PublishAsync(It.IsAny<ICommand<UserAggregate, UserId, IExecutionResult>>(),
|
||||
// // It.IsAny<CancellationToken>())).Returns(() => Task.FromResult(ExecutionResult.Success()));
|
||||
|
||||
// // await Sut.HandleAsync(domainEvent, _sagaContext.Object, CancellationToken.None);
|
||||
// // await Sut.PublishAsync(_commandBus.Object, CancellationToken.None);
|
||||
|
||||
// // Sut.UncommittedEvents.Single().AggregateEvent.ShouldBeOfType<MessageSagaStartedEvent>();
|
||||
// // _commandBus.Verify(c => c.PublishAsync(It.IsAny<ICommand<UserAggregate, UserId, IExecutionResult>>(),
|
||||
// // It.IsAny<CancellationToken>()), Times.Once);
|
||||
// //}
|
||||
|
||||
|
||||
// public static IEnumerable<object[]> GetSendMessageData()
|
||||
// {
|
||||
// yield return new object[] { new Peer(PeerType.User, 1), new Peer(PeerType.User, 2) };
|
||||
// yield return new object[] { new Peer(PeerType.User, 1), new Peer(PeerType.Chat, 2) };
|
||||
// yield return new object[] { new Peer(PeerType.User, 1), new Peer(PeerType.Channel, 2) };
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,41 @@
|
||||
using MyTelegram.Domain.Sagas.Events;
|
||||
|
||||
namespace MyTelegram.Domain.Tests.UnitTests.Sagas;
|
||||
|
||||
public class UserSignInSagaTests : TestsFor<SignInSaga>
|
||||
{
|
||||
private readonly Mock<ISagaContext> _sagaContext;
|
||||
|
||||
public UserSignInSagaTests()
|
||||
{
|
||||
Fixture.Customize<AppCodeId>(c => c.FromFactory(() => AppCodeId.Create("0", "0")));
|
||||
Fixture.Customize<SignInSagaId>(c => c.FromFactory(() => new SignInSagaId($"signinsagaid-{Guid.Empty}")));
|
||||
_sagaContext = InjectMock<ISagaContext>();
|
||||
//var idGenerator = InjectMock<IIdGenerator>();
|
||||
//IdGeneratorFactory.SetDefaultIdGenerator(idGenerator.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SignIn_With_Invalid_PhoneCode_Throws_Exception()
|
||||
{
|
||||
var aggregateEvent = new CheckSignInCodeCompletedEvent(A<RequestInfo>(), false, 1);
|
||||
var domainEvent =
|
||||
ADomainEvent<AppCodeAggregate, AppCodeId, CheckSignInCodeCompletedEvent>(aggregateEvent, A<AppCodeId>(), 1);
|
||||
|
||||
var exception = await Assert.ThrowsAsync<RpcException>(async () => await Sut.HandleAsync(domainEvent, _sagaContext.Object, CancellationToken.None).ConfigureAwait(false));
|
||||
|
||||
exception.RpcError.ShouldBe(RpcErrors.RpcErrors400.PhoneCodeInvalid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SignIn_With_Correct_PhoneCode_Success()
|
||||
{
|
||||
var aggregateEvent = new CheckSignInCodeCompletedEvent(A<RequestInfo>(), true, 1);
|
||||
var domainEvent =
|
||||
ADomainEvent<AppCodeAggregate, AppCodeId, CheckSignInCodeCompletedEvent>(aggregateEvent, A<AppCodeId>(), 1);
|
||||
|
||||
await Sut.HandleAsync(domainEvent, _sagaContext.Object, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
Sut.UncommittedEvents.Single().AggregateEvent.ShouldBeOfType<SignInStartedSagaEvent>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using MyTelegram.Domain.Sagas.Events;
|
||||
|
||||
namespace MyTelegram.Domain.Tests.UnitTests.Sagas;
|
||||
|
||||
public class UserSignUpSagaTests : TestsFor<UserSignUpSaga>
|
||||
{
|
||||
private readonly Mock<ISagaContext> _sagaContext;
|
||||
|
||||
public UserSignUpSagaTests()
|
||||
{
|
||||
Fixture.Customize<AppCodeId>(c => c.FromFactory(() => AppCodeId.Create("0", "0")));
|
||||
Fixture.Customize<UserSignUpSagaId>(c => c.FromFactory(() => new UserSignUpSagaId($"usersignupsagaid-{Guid.Empty}")));
|
||||
_sagaContext = InjectMock<ISagaContext>();
|
||||
//var idGenerator = InjectMock<IIdGenerator>();
|
||||
//IdGeneratorFactory.SetDefaultIdGenerator(idGenerator.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SignUp_For_New_User_Success()
|
||||
{
|
||||
var aggregateEvent = new CheckSignUpCodeCompletedEvent(A<RequestInfo>(), true, 0, 0, "0", "0", null);
|
||||
var domainEvent = new DomainEvent<AppCodeAggregate, AppCodeId, CheckSignUpCodeCompletedEvent>(aggregateEvent,
|
||||
Metadata.Empty,
|
||||
A<DateTimeOffset>(),
|
||||
A<AppCodeId>(),
|
||||
1);
|
||||
|
||||
await Sut.HandleAsync(domainEvent, _sagaContext.Object, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
Sut.UncommittedEvents.Single().AggregateEvent.ShouldBeOfType<UserSignUpSuccessSagaEvent>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user