是否可以在ExUnit测试中存根(模拟?)Ecto.UUID.generate?(Is it possible to stub(mock?) Ecto.UUID.generate in an ExUnit test?)
我正在使用
Ecto.UUID.generate
在用户模型上创建随机令牌。在我的ExUnit测试中,我想测试调用创建路由的控制器,但是因为令牌总是随机的,所以我无法确定性地测试结果。
理想情况下,我希望能够在我的测试中存根
Ecto.UUID.generate
,因此它始终创建相同的UUID,以便我可以正确地测试响应。谢谢 :)
I'm using
Ecto.UUID.generate
to create a random token on a user model.In my ExUnit test, I want to test the controller that calls the creation route, however because the token is always random, I can't deterministically test the result.
Ideally, I want to be able to stub the
Ecto.UUID.generate
in my test so it always creates the same UUID so I can test the response correctly.Thanks :)
原文:https://stackoverflow.com/questions/30093551
最满意答案
工作大部分时间和失败有时看起来像一个竞争条件。 Andrew Whitechapel撰写了与
RequestComAddInAutomationService
1相关的竞争条件:虽然他说竞争条件不应该是进程内VBA宏的问题,但问题可能发生在您的特定场景中。
尝试建议的解决方法并循环,直到您的
Addin.Object
有效(C#代码,类似于VBA):while (utils == null) { utils = (ComServiceOleMarshal.IAddinUtilities)addin.Object; System.Threading.Thread.Sleep(100); } utils.DoSomething();
1关于你正在做的事情,他的博客上有很多有用的信息,所以千万不要错过相关的文章。
Turned out that Excel disabled the COM add-in. This is known to sometimes happen silently, without Excel complaining about anything.
So, since the add-in was registered with excel, the following line succeeded:
Set addin = Application.COMAddIns("My AddIn")
But since it was disabled, the object was not created and
Set automationObject = addin.Object
resulted in
Nothing
.
相关问答
更多-
只有Variant可以为Null ,而不是使用Nothing : Public Function parseEmployee(ByVal employeeId As Integer, _ ByVal ws As Worksheet) As employee Dim emp As New employee Dim empRow As Range If sheetContainsEmployee(employeeId, ...
-
页面中有一个iframe。 这就是问题所在。 您必须首先获取iframe元素,然后获取与iframe关联的文档。 fileupload按钮位于iframe中。 IE.navigate "https://www.earthpoint.us/ExcelToKml.aspx" 'Show Window IE.Visible = True 'Wait for loaded WaitIE IE 'Select document Set IEDoc = IE.document Dim iBox As HTMLIFr ...
-
为什么它返回null?(why it returns null?)[2023-07-23]
原因之一 - 在MainFrame中调用getStudentsPass()时,尚未设置密码。 原因二 - 您在MainFrame中使用的SystemManagement对象和您在AddStudent中获得的SystemManagement对象完全不一样。 很难说没有更多的代码。 但我更喜欢Reason One - 检查程序流程,密码何时设置,什么时候尝试获取。 Reason one - password has not been set, when you call getStudentsPass() in ... -
单独填充10000个单元会让您觉得VSTO非常慢。 我可以用你提到的动态数组方法在很短的时间内完成它: static public void PopulateABigNumberOfCells(Excel.Application xlApp, DataTable dataTable) { //Turn off Excel updating SwitchApplicationSettings(xlApp,false); //Populate a 2D array - via a DataTable in t ...
-
Outlook API不是本机.NET框架。 为了与之交互,.NET依赖于编组和插入程序集,从而使其更容易出错和不稳定。 从我迄今为止看到的outlook API经验来看,我会坚持使用VBA,如果你遇到很多麻烦,你应该考虑检索暴露outlook扩展MAPI的第三方库。 Outlook API is not native .NET framework. To interact it with, .NET relies on marshaling and interrop assembly thus makin ...
-
事实证明函数的Null值被传递给Date / Time变量。 我通过使用以下内容修复了这个问题: dim myDate as date dim myVar as variant myVar=getTableValue(idNum,"thisTable","idField", "valueField") if isNull(myVar) then myDate=0 else myDate=myVar endif 虽然它不检查myVar是否返回Date,但valueField的值是Date / Time ...
-
GetOpenFileNameW在VBA中?(GetOpenFileNameW in VBA?)[2022-12-19]
您目前的问题似乎是OpenFile.lStructSize = LenB(strFile) 由于您将strFile设置为257,因此它包含574个字节。 基于结果,它看起来像lStructSize只会适用于文件,所以你必须使用你原来的OpenFile.lStructSize = LenB(OpenFile) 另外我不认为strptr的工作方式与你使用它的方式不同,它将字符串转换为指针,但反之亦然 如果这确实是问题之一,我写了一个将指针转换为字符串的函数。 不幸的是,它需要你传递长度,我试图从指针本身获取它时 ... -
所以@Dmitry提供的链接就是我所需要的。 通过使用运行对象表(ROT),我能够获得对Outlook加载的Outlook插件的引用。 因此,允许我调用其中的方法来删除邮件附件。 需要进行一些更改,包括: 将插件注册到ThisAddin_Startup()作为默认的OutlookAddin类使用静态构造函数,因此我无法在构造函数中引用Addin。 我还必须将我的代码移动到用户会话进程,因为这个帖子COMException(0x800401E3):具有计划任务的操作不可用(来自HRESULT的异常:0x800 ...
-
VBA中的VSTO:AddIn.Object有时会返回Nothing(null)(VSTO in VBA: AddIn.Object returns Nothing (null) sometimes)[2023-08-22]
工作大部分时间和失败有时看起来像一个竞争条件。 Andrew Whitechapel撰写了与RequestComAddInAutomationService 1相关的竞争条件: COMAddIns比赛条件 虽然他说竞争条件不应该是进程内VBA宏的问题,但问题可能发生在您的特定场景中。 尝试建议的解决方法并循环,直到您的Addin.Object有效(C#代码,类似于VBA): while (utils == null) { utils = (ComServiceOleMarshal.IAddinUti ... -
在这里找到了一个更好的解决方案http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/afd7f2ab-ee1e-495f-8071-9f2377a603fb private void FindUsedRange() { Excel.Worksheet wks = this.ActiveSheet as Excel.Worksheet; if (wks != null) { wks.UsedRange.Sel ...